0

please can anyone help me with this. It says my function is not defined.

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.speedyshare.com/")

frame_name = driver.find_elements_by_xpath("/html/frameset/frame").get_attribute("name")

driver.switch_to.frame(frame_name)

elem = driver.find_element_by_id("selectfilebox")
elem.click()

I get this traceback.

Traceback (most recent call last):
  File "/home/ro/selem.py", line 6, in <module>
    frame_name = driver.find_elements_by_xpath("/html/frameset/frame").get_attribute("name")
AttributeError: 'list' object has no attribute 'get_attribute'
>>> 

EDIT:

When I run

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.speedyshare.com/")

driver.switch_to.frame(0)

elem = driver.find_element_by_id("selectfilebox")
elem.click()

AND

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.speedyshare.com/")

frame_name = driver.find_elements_by_xpath("/html/frameset/frame").get_attribute("name")

driver.switch_to.frame(frame_name)

elem = driver.find_element_by_id("selectfilebox")
elem.click()

They both keep running with no tracebacks but the mouse stays in the address bar.

3
  • 1
    find_elements_by_xpath returns a list. List objects do not have a get_attribute method. Commented Sep 28, 2015 at 16:36
  • 1
    Did you mean find_element_by_xpath (note singular)? Commented Sep 28, 2015 at 16:36
  • no, I've tried that also but I don't get a traceback and the mouse just stays in the address bar. Commented Sep 28, 2015 at 16:42

1 Answer 1

2

While @Kevin and @jonrsharpe points are perfectly correct, you don't even need this line:

frame_name = driver.find_elements_by_xpath("/html/frameset/frame").get_attribute("name")

You can simply pass the frame name to switch to:

driver.switch_to.frame("frame_name")

Or, the frame index (looks like it's just the first iframe on the page):

driver.switch_to.frame(0)

And selenium webdriver will take care of locating the frame and switching to it.

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

3 Comments

Thankyou but the frame is dynamic, I got that line from here. stackoverflow.com/questions/17954652/…
@booberz okay, you can then switch to it by index (see the update). Thanks.
@booberz also fixed the linked answer, thanks for pointing that.

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.