我無(wú)法從網(wǎng)站上的下拉菜單中選擇復(fù)選框。下拉菜單位于 iframe 內(nèi),當(dāng)我嘗試切換到 iframe 時(shí),我不斷收到TimeoutException消息:。下面是我正在嘗試的代碼和 HTML。我是 Python 的新手,所以對(duì)此的任何幫助將不勝感激。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貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊
要在而不是中切換Selenium的焦點(diǎn),您必須:<iframe>
presence_of_element_located()
誘導(dǎo)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']")))
注意:您必須添加以下導(dǎo)入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
添加回答
舉報(bào)
0/150
提交
取消