提问者:小点点

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


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

在我得到错误,由于加载状态,我降级到chrome102.Now我面临这个错误,我不能理解。我分享我的控制台和脚本:

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)"); 

共2个答案

匿名用户

要单击元素不,谢谢而不是visibilityOfElement定位(),您需要诱导WebDriver等元素ToBeClickable(),并且您可以使用以下任一定位器策略:

>

  • 使用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();
    

  • 匿名用户

    看来引入了bughttps://chromedriver.chromium.org/downloads

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

    修复了Chrome驱动程序版本104