警告:无法找到与 126...Selenium Java 匹配的 CDP 实现

问题描述 投票:0回答:1

我是 Selenium 新手,这是我想要执行的代码 Google Chrome 打开,点击“自动完成”,但无法填写表格!? 这是我收到的错误,它可能与 google chrome 版本有关。

import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class SeleniumBasics {
    
public static void main(String[] args) throws InterruptedException {  
    
    WebDriver driver= new ChromeDriver();  
    driver.get("https://formy-project.herokuapp.com/");
    driver.manage().window().maximize(); 
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    driver.findElement(By.xpath("//a[@class='btn btn-lg' and text()='Autocomplete']")).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='btn btn-lg' and text()='Autocomplete']"))).click();        
    wait.until(ExpectedConditions.elementToBeClickable(By.id("autocomplete"))).sendKeys("1555 Park Blvd, Palo Alto, CA");
    Thread.sleep(1000);
    
}  

}

这是错误消息...非常感谢您的帮助...谢谢

juin 28, 2024 12:35:09 P.M. org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find CDP implementation matching 126
juin 28, 2024 12:35:09 P.M. org.openqa.selenium.chromium.ChromiumDriver lambda$new$5
WARNING: Unable to find version of CDP to use for 126.0.6478.115. You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.16.1` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //a[@class='btn btn-lg' and text()='Autocomplete'] (tried for 10 second(s) with 500 milliseconds interval)
    at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:84)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:229)
    at SeleniumBasics.main(SeleniumBasics.java:18)
Caused by: org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
  (Session info: chrome=126.0.6478.115)
Build info: version: '4.16.1', revision: '9b4c83354e'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '22'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [5944275f9cbce6396f8f664983b0bbe8, findElement {using=xpath, value=//a[@class='btn btn-lg' and text()='Autocomplete']}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 126.0.6478.115, chrome: {chromedriverVersion: 126.0.6478.126 (d36ace6122e..., userDataDir: C:\Users\Kamilia\AppData\Lo...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:56029}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: windows, proxy: Proxy(), se:cdp: ws://localhost:56029/devtoo..., se:cdpVersion: 126.0.6478.115, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: 5944275f9cbce6396f8f664983b0bbe8
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:52)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:191)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:200)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:175)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:523)
    at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:165)
    at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:59)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:354)
java selenium-webdriver
1个回答
0
投票

就 CDP 警告而言,您可以在 here 找到类似问题的答案。出现错误是因为您在单击“自动完成”按钮元素后等待它。所以你可以更改代码如下 `public static void main(String[] args) 抛出 InterruptedException {

WebDriver driver= new ChromeDriver();  
driver.get("https://formy-project.herokuapp.com/");
driver.manage().window().maximize(); 
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
//driver.findElement(By.xpath("//a[@class='btn btn-lg' and text()='Autocomplete']")).click();//you can comment this line because the below line is doing the same after waiting for the elment to be clickable
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='btn btn-lg' and text()='Autocomplete']"))).click();        
wait.until(ExpectedConditions.elementToBeClickable(By.id("autocomplete"))).sendKeys("1555 Park Blvd, Palo Alto, CA");
Thread.sleep(1000);

} `

© www.soinside.com 2019 - 2024. All rights reserved.