Reputation: 431
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.
Upvotes: 0
Views: 1913
Reputation: 473993
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.
Upvotes: 2