无法在 Java-Selenium 中定位元素错误
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
。点击 you can use either of the following :
xpath
:
driver.findElement(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']")).click();
理想情况下 click()
在你需要诱导的元素上 for the elementToBeClickable()
and you can use either of the following :
xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']"))).click();
弹出通知
您可以在以下位置找到一些关于处理通知弹出窗口的相关讨论:
我写过代码:
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
。点击
xpath
:driver.findElement(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']")).click();
理想情况下 click()
在你需要诱导的元素上 elementToBeClickable()
and you can use either of the following
xpath
:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']"))).click();
弹出通知
您可以在以下位置找到一些关于处理通知弹出窗口的相关讨论: