selenium.WebDriverException:未知错误:尝试获取页面源时无法反序列化从 Runtime.callFunctionOn 收到的结果值

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

在尝试使用 selenium 获取页面源代码时,我开始收到以下错误。

我的java代码如下所示:

private String getPageContentRaw(String URL, Long waitDelay, Long waitForPageLoadPollInterval) throws Exception {
    try {
        this.driver.get(URL);
    } catch (Exception e) {
        Thread.sleep(1500);
        this.driver.get(URL);
    }
     
    waitForPageToLoad(waitDelay, waitForPageLoadPollInterval);

    return this.driver.getPageSource();
}

调用时抛出错误:

this.driver.getPageSource();

知道是什么原因造成的吗?

谢谢

org.openqa.selenium.WebDriverException: unknown error: cannot deserialize the result value received from Runtime.callFunctionOn
  (Session info: chrome=123.0.6312.122)
Build info: version: '4.16.1', revision: '9b4c83354e'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.8.5-201.fc39.x86_64', java.version: '21.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [80030c19b0e32fb50aaa2dbecd4b0d2d, getPageSource {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 123.0.6312.122, chrome: {chromedriverVersion: 123.0.6312.122 (31f8248cdd9...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:9999}, pageLoadStrategy: normal, platformName: any, proxy: Proxy(), se:cdp: ws://localhost:9999/devtool..., se:cdpVersion: 123.0.6312.122, setWindowRect: false, 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: 80030c19b0e32fb50aaa2dbecd4b0d2d
        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.RemoteWebDriver.execute(RemoteWebDriver.java:596)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
        at org.openqa.selenium.remote.RemoteWebDriver.getPageSource(RemoteWebDriver.java:386)
        at 
java selenium-webdriver
1个回答
0
投票

我刚刚得到了相同的“WebDriverException:未知错误:无法反序列化从 Runtime.callFunctionOn 收到的结果值”

就我而言,它是 selenium+python3 和 .text 方法。我一开始感到困惑,因为这种情况并非每次都会发生,但后来我发现页面的部分在错误出现时发生了变化。 尝试将异常视为 StaleElementException 来处理。我很久以前就遇到过 Selenium 的这种行为。

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