提问人:ever alian 提问时间:6/29/2022 最后编辑:ever alian 更新时间:7/1/2022 访问量:182
Selenium 复选框找不到 - Web 驱动程序预期条件失败:等待 By.xpath 找到的元素的可见性:
Selenium Checkbox cannot find - web driver Expected condition failed: waiting for visibility of element located by By.xpath:
问:
我正在尝试将 selenium 用于无头浏览器以触发一些输入,但页面中的一个复选框无法识别。我尝试等待 100 秒,没有等待,但仍然有相同的错误,该元素找不到。
下面是代码。我尝试了 ID 和 xPath,两者都有相同的错误。也有和但同样的错误。visibilityOfElementLocated
elementToBeClickable
当我尝试 chrome inspect 元素中的 xpath 时,它只找到一个元素。所以我认为 xpath 是正确的。
val wait = WebDriverWait(driver, 30)
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@name = 'element_ID']")))
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@name = 'element_ID']")))
val elem: WebElement = driver.findElement(By.xpath("//*[@id = 'element_ID']"))
elem.click()
错误
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element
to be clickable: By.xpath: //*[@name = 'element_ID'] (tried for 30 second(s) with 500 milliseconds interval)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'xxx', ip: 'xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.4', java.version: '1.8.0_321'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.38.552518 (183d19265345f5..., userDataDir: /var/folders/06/072_bdvx0rs...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 103.0.5060.53, webStorageEnabled: true}
Session ID: 2d1c4aab1e9780033abcd6891537a5dsf
答: 暂无答案
评论