首页 > 解决方案 > 如何使用 selenium Python 单击框架和 iFrame 中的项目

问题描述

我要做的是单击此复选框。但是,它在 iframe 和框架中。我不确定如何选择这个。我继续得到一个未找到的元素。我已经通过 ID、名称和 Xpath 进行了尝试。

HTML:

<iframe id="myframe" style="background-color: rgb(255, 255, 255); width: 100%; position: absolute; height: 829px; display: block;" src="/f5-w-687474703a2f2f6e617973636c75737465722e6e63722e636f6d3a3830$$/MSL/jsp/MSLReDirect.jsp?ep=GIMV">
<frameset rows="100%,*" framespacing="false" frameborder="0" scrolling="No" noresize="" marginwidth="0" marginheight="0" border="false">
<frame src="f5-h-$$/GIM/GIM?TARGET_PROCESSOR=com.ncr.gim.processor.OPFProcessor&amp;REQ=GIMA&amp;pageAccess=&amp;LAZ=Wed Mar 31 15:04:02 EDT 2021" name="GIMA" frameborder="0" border="0" scrolling="auto">
<input type="checkbox" id="StatusCheck" name="StatusCheck">
</frame>
</frameset>
</iframe>

我的脚本

driver.implicitly_wait(10)
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
driver.switch_to.frame(driver.find_element_by_tag_name("frame"))
WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="Advanced3"]/input[1]'))).sendkeys("test")
driver.switch_to.default_content()

标签: pythonpython-3.xseleniumselenium-webdriverselenium-chromedriver

解决方案


推荐阅读