Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java Selenium中找不到元素错误_Java_Selenium_Selenium Webdriver_Xpath_Webdriverwait - Fatal编程技术网

在Java Selenium中找不到元素错误

在Java Selenium中找不到元素错误,java,selenium,selenium-webdriver,xpath,webdriverwait,Java,Selenium,Selenium Webdriver,Xpath,Webdriverwait,我编写了以下代码: WebDriverWait wait = new WebDriverWait(driver, 10); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("New CDA Request"))); element.click(); 运行脚本时出现以下错误: ChromeDriver was started successfu

我编写了以下代码:

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请求是
文本内容。要单击,可以使用以下任一选项:

  • xpath

    driver.findElement(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']")).click();
    
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']"))).click();
    

理想情况下,在需要为
元素归纳的元素上单击()
,以便将
元素归纳为可折叠()
,您可以使用以下任一选项:

  • xpath

    driver.findElement(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']")).click();
    
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(@class, 'slds-button') and text()='New CDA Request']"))).click();
    

通知弹出窗口 您可以在以下位置找到关于处理弹出通知的相关讨论:


我们如何知道如何从一个屏幕快照访问该元素,而不知道带有类名和ID的实际html?也许
By.className(“新CDA请求”)
是正确的,但据我所知,css类名不能包含空格,因此选择器对我来说很可疑。有关路径,请参阅所附图片。让我知道该走哪条路。@Shalu很高兴能帮助你。请点击“我的答案”旁边的空心记号(位于votedown箭头下方)来输入答案,这样记号就会变成绿色。