2

I need to run thousands of searches on a certain database and I'm using Python and Selenium WebDriver to automate it. The thing is, the frame that contains the search results has a name that is dynamically generated. That name always begins the same way (say, "results_frame") and then it's followed by a bunch of numbers that change every time (like "results_frame1298120910290"). So, based on a few hours of googling, I tried using xpath:

framename = driver.find_elements_by_xpath("//frame[contains(@name, 'results_frame')]")
driver.switch_to_frame(framename)

No good. When I print 'framename', what I get is this:

[<selenium.webdriver.remote.webelement.WebElement object at 0x101206350>,    <selenium.webdriver.remote.webelement.WebElement object at 0x101206390>]

Instead of the actual name of the frame.

I've also tried using indexes (as in driver.switch_to_frame(0), driver.switch_to_frame(1), etc), as suggested here, but no good either.

So, how can I retrieve a frame's name when that name is dynamically generated? Any thoughts?

(Python 2.7.5, Selenium 2.2.0, Mac OS X 10.6.8, Firefox 22.0)

1
  • 1
    I hope Richard have answered you so quick. Whenever doing xpath practice using .// instead of // Commented Jul 30, 2013 at 18:38

1 Answer 1

7

find_elements_by_xpath returns an object of type WebElement. You need to use get_attribute to retrieve the value of an attribute from the WebElement.

framename = driver.find_element_by_xpath("//frame[contains(@name, 'results_frame')]").get_attribute("name")

That should return the name you're looking for.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.