[英]Unable to locate element error in Java-Selenium
我已经写了代码:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("New CDA Request")));
element.click();
运行脚本时出现以下错误:
ChromeDriver was started successfully.
Feb 15, 2021 5:18:36 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.className: New CDA Request (tried for 10 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at Automation.CreateCDARequest.main(CreateCDARequest.java:30)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":".New\ CDA\ Request"}
(Session info: chrome=88.0.4324.150)
在出现错误之前,我会在屏幕上弹出一个允许通知的窗口。 弹出窗口是否创建问题?
请建议。
新 CDA 请求是<button>
的textContent
。 要单击WebElement ,您可以使用以下任一Locator Strategies :
xpath
:
driver.findElement(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']")).click();
理想情况下,要在需要为elementToBeClickable()
诱导WebDriverWait的元素上click()
,您可以使用以下任一定位器策略:
xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']"))).click();
您可以在以下位置找到一些有关处理通知弹出窗口的相关讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.