我无法从网站上的下拉菜单中选择复选框。下拉菜单位于 iframe 内,当我尝试切换到 iframe 时,我不断收到TimeoutException消息:。下面是我正在尝试的代码和 HTML。我是 Python 的新手,所以对此的任何帮助将不胜感激。Python:wait = WebDriverWait(driver, 20)frm1= wait.until(EC.presence_of_element_located((By.ID, "ReportViewerControl_ctl04_ctl03_ctl01")))driver.switch_to.frame(frm1)HTML:<iframe id="ReportViewerControl_ctl04_ctl03_ctl01" onclick="event.cancelBubble=true;" onactivate="event.cancelBubble=true;" style="display: block; position: absolute; z-index: 10; left: 208px; top: 35px; width: 198px; height: 166px;" src="javascript:'';" frameborder="0" title="Area place holder" longdesc="Area place holder" name="ReportViewerControl_ctl04_ctl03_ctl01"></iframe>
1 回答
杨__羊羊
TA贡献1943条经验 获得超7个赞
要在而不是中切换Selenium的焦点,您必须:<iframe>
presence_of_element_located()
诱导WebDriverWait以等待所需的框架可用并切换到它。
您可以使用以下任一定位器策略:
使用
CSS_SELECTOR
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='ReportViewerControl'][longdesc='Area place holder']")))
使用
XPATH
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[starts-with(@id, 'ReportViewerControl') and @title='Area place holder']")))
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
添加回答
举报
0/150
提交
取消