【发布时间】:2021-05-18 08:23:17
【问题描述】:
我已经写了代码:
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)
在出现错误之前,我会在屏幕中弹出一个允许通知的窗口。弹出窗口是否创建问题?
请提出建议。
【问题讨论】:
-
在不知道带有类名和 id 的实际 html 的情况下,我们应该如何知道如何从屏幕截图中访问该元素?也许
By.className("New CDA Request"))是正确的,但据我所知,css 类名不能包含空格,所以选择器对我来说看起来很可疑。 -
路径请参考附图。让我知道使用什么路径。
标签: java selenium selenium-webdriver xpath webdriverwait