我有這個 html:
<input _wad-f341 type="text" autocomplete="off" kkwdnkwn class="classname" placeholder="Search here" id="ppui-search-0-input">
使用開發人員工具我得到了 xpath,我使用下面的代碼來檢查搜索區域是否已加載。
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//*[@id='ppui-search-0-input']")))
由于未找到元素,我正在超時。誰能幫幫我嗎?除了使用占位符描述之外,還有其他方法嗎?
uj5u.com熱心網友回復:
理想情況下,要定位可點擊元素而不是presence_of_element_located(),您需要為element_to_be_clickable()引入WebDriverWait,您可以使用以下任一定位器策略:
使用
CSS_SELECTOR:element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.classname[placeholder='Search here'][id^='ppui-search']")))使用
XPATH:element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='classname' and @placeholder='Search here'][starts-with(@id, 'ppui-search')]")))注意:您必須添加以下匯入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/362312.html
標籤:蟒蛇-3.x 硒 路径 css-选择器 网络驱动程序等待
下一篇:我收到錯誤-**ThemethodgetAttribute(String)isundefinedforthetypeObject**,如何解決這個錯誤?
