繁体   English   中英

线程“主”org.openqa.selenium.WebDriverException 中的异常:未知错误:使用 Selenium Java 的意外命令响应

[英]Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: unexpected command response using Selenium Java

我在 Eclipse 中使用 Selenium,我经常收到这些错误。

在由于加载状态而出现错误之前,我降级到 chrome 102。现在我面临这个我无法理解的错误。 我正在共享我的控制台和脚本:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: unexpected command response
  (Session info: chrome=103.0.5060.114)
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'AWAIS-PC', ip: '192.168.1.62', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [b494462d4f7752feaa9aeeb67f469204, findElement {using=id, value=wzrk-cancel}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 103.0.5060.114, chrome: {chromedriverVersion: 102.0.5005.61 (0e59bcc00cc4..., userDataDir: C:\Users\WRP\AppData\Local\...}, goog:chromeOptions: {debuggerAddress: localhost:54170}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:54170/devtoo..., se:cdpVersion: 103.0.5060.114, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: b494462d4f7752feaa9aeeb67f469204
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
    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:53)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
    at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:162)
    at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:60)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:387)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:379)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:197)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:193)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
    at First_Test.Practice_First.main(Practice_First.java:52)
WebDriverManager.chromedriver().driverVersion("102.0.5005.61").setup();
WebDriver driver = new ChromeDriver();
WebDriverWait waits=new WebDriverWait (driver, Duration.ofSeconds(13));
//driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
driver.get("https://www.ounass.ae/");
//Thread.sleep(3000);
driver.manage().window().maximize();
//Thread.sleep(3000);
//  String originalWindow=  driver.getWindowHandle();
// Thread.sleep(5000);
waits.until(ExpectedConditions.visibilityOfElementLocated(By.id("wzrk-cancel")));
driver.findElement(By.id("wzrk-cancel")).click();
// driver.findElement(By.xpath("//button[@id='wzrk-cancel']")).click();
waits.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("a[href*='/men']")));
driver.findElement(By.cssSelector("a[href*='/men']")).click();
JavascriptExecutor Js1 = (JavascriptExecutor) driver;
Js1.executeScript("window.scrollBy(0,2500)"); 

要单击元素不,谢谢,而不是visibilityOfElementLocated() ,您需要为elementToBeClickable()诱导WebDriverWait ,您可以使用以下任一定位器策略

  • 使用id

     new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.id("birtviewer"))).click();
  • 使用cssSelector

     new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button#wzrk-cancel"))).click();
  • 使用xpath

     new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='wzrk-cancel']"))).click();

看起来已经引入了一个错误 - https://chromedriver.chromium.org/downloads

Resolved issue 4121: WebDriver command sometimes fails with "unexpected command response"

已在 Chrome 驱动程序版本 104 中修复

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM