I have been trying to click an accept button in an iframe
, but I am unable to locate this iframe
with xpath
. I have checked similar SO posts but to no avail.
Selenium can't locate iframe , python selenium cant find iframe xpath
I have tried following so far.
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"pop-frame028142186741537767")))
gives TimeoutException
.
Also tried:
time.sleep(10)
driver.switch_to.frame(driver.find_element_by_xpath("//div[@class='truste_box_overlay']/div[@class='truste_box_overlay_inner']/iframe[@id='pop-frame028142186741537767']"))
Error
NoSuchElementException: Unable to locate element: //div[@class='truste_box_overlay']/div[@class='truste_box_overlay_inner']/iframe[@id='pop-frame028142186741537767']
Finding the the iframe
driver.find_elements_by_id('pop-frame028142186741537767')
gives an empty list. However, I am able to locate two parent div
elements with xpath
and class
attributes.
EDIT : driver.find_elements_by_class_name('truste_box_overlay')
gives outermost div
element. But, accessing same element with id
driver.find_elements_by_id('pop-div20738421000570183')
gives empty list.
So, I suppose find_elements_by_id
not working?? How can I go about to solve this problem. I am not able to progress as without clicking this button I can't interact to the main content.
Switch back to the default content (out of the ):
driver.switch_to.default_content()
driver.switch_to.frame("iframe name")
driver.find_elements_by_class_name('truste_box_overlay')
Hope this will fix your issue.
You are searching by an ID which is auto-generated and will not work the next time the page is reloaded. Instead try XPath using partial search //iframe[contains(@id, 'pop-frame')]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.