ВНИМАНИЕ: невозможно найти реализацию CDP, соответствующую 126...Selenium Java

Я новичок в 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)
Пользовательский скаляр GraphQL
Пользовательский скаляр GraphQL
Листовые узлы системы типов GraphQL называются скалярами. Достигнув скалярного типа, невозможно спуститься дальше по иерархии типов. Скалярный тип...
Как вычислять биты и понимать побитовые операторы в Java - объяснение с примерами
Как вычислять биты и понимать побитовые операторы в Java - объяснение с примерами
В компьютерном программировании биты играют важнейшую роль в представлении и манипулировании данными на двоичном уровне. Побитовые операции...
Поднятие тревоги для долго выполняющихся методов в Spring Boot
Поднятие тревоги для долго выполняющихся методов в Spring Boot
Приходилось ли вам сталкиваться с требованиями, в которых вас могли попросить поднять тревогу или выдать ошибку, когда метод Java занимает больше...
Полный курс Java для разработчиков веб-сайтов и приложений
Полный курс Java для разработчиков веб-сайтов и приложений
Получите сертификат Java Web и Application Developer, используя наш курс.
0
0
749
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Что касается предупреждения CDP, вы можете найти ответ на аналогичную проблему здесь. Что касается вашей ошибки, то это связано с тем, что вы ожидаете элемента кнопки автозаполнения после нажатия на него (кнопка автозаполнения исчезнет, ​​как только вы нажмете на нее, поскольку приложение перейдет на следующую страницу, где кнопка автозаполнения отсутствует). Итак, вы можете изменить код ниже

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();//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);
}

Другие вопросы по теме