Why can Selenium not access these dynamically loaded elements?
Question:
There should be seven elements whose class is “top_search”. However, an empty list is printed with the following despite using implicitly_wait:
driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(30)
driver.get('http://www.egglandsbest.com/where-to-buy/')
print driver.find_elements_by_css_selector('div[class="top_search"]')
Answers:
You need to switch to an iframe:
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.implicitly_wait(10)
driver.get("http://www.egglandsbest.com/where-to-buy/")
driver.switch_to.frame(driver.find_element_by_id("destini"))
print driver.find_elements_by_xpath('//div[@class="top_search"]')
I just had a quick look at the source to pull that,there are numerous iframes so you will have to sift through and see which ones you need.
There should be seven elements whose class is “top_search”. However, an empty list is printed with the following despite using implicitly_wait:
driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(30)
driver.get('http://www.egglandsbest.com/where-to-buy/')
print driver.find_elements_by_css_selector('div[class="top_search"]')
You need to switch to an iframe:
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.implicitly_wait(10)
driver.get("http://www.egglandsbest.com/where-to-buy/")
driver.switch_to.frame(driver.find_element_by_id("destini"))
print driver.find_elements_by_xpath('//div[@class="top_search"]')
I just had a quick look at the source to pull that,there are numerous iframes so you will have to sift through and see which ones you need.