繁体   English   中英

无法在 python Z8E00596AD8DE2213FF8F8D8478D5362ZC 中找到具有 xpath 和 id 的 iframe

[英]unable to locate iframe with xpath and id in python selenium

我一直在尝试单击iframe中的接受按钮,但我无法使用xpath iframe 我检查了类似的 SO 帖子,但无济于事。

Selenium can't locate iframe , python selenium cant find iframe xpath

这是页面的 HTML。

到目前为止,我已经尝试过。

wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"pop-frame028142186741537767")))给出TimeoutException

也试过:

time.sleep 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']"))

错误

NoSuchElementException: Unable to locate element: //div[@class='truste_box_overlay']/div[@class='truste_box_overlay_inner']/iframe[@id='pop-frame028142186741537767']

找到iframe driver.find_elements_by_id('pop-frame028142186741537767')给出一个空列表。 但是,我能够找到具有xpathclass属性的两个父div元素。

编辑driver.find_elements_by_class_name('truste_box_overlay')给出最外层的div元素。 但是,使用id driver.find_elements_by_id('pop-div20738421000570183')访问相同的元素会给出空列表。

所以,我想find_elements_by_id不起作用? 我怎样才能解决这个问题。 我无法前进,因为如果不单击此按钮,我将无法与主要内容进行交互。

切换回默认内容(在 之外):

driver.switch_to.default_content()

driver.switch_to.frame("iframe name")

driver.find_elements_by_class_name('truste_box_overlay')

希望这能解决您的问题。

您正在按自动生成的 ID 进行搜索,下次重新加载页面时将无法使用。 而是尝试 XPath 使用部分搜索 //iframe[contains(@id, 'pop-frame')]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM