当前位置: 首页 > 知识库问答 >
问题:

使用java在使用selenium的chrome中未打开网页

太叔英卫
2023-03-14
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: unable to discover open page

浏览器正在打开,但所需的网页未打开

已尝试卸载(还删除了用户数据)

使用JDK 8,

硒3.6.0Java,

chrome浏览器最新版本,

chrome驱动程序不确定(可能是2.31)

我的代码

package newPackage;

  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;

  public class MyClass {
        public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver_Selenium\\chromedriver.exe"); 

        WebDriver driver=new ChromeDriver(); 
        driver.get("http://google.com"); 
  }
}

我看到的输出

Starting ChromeDriver (v2.3) on port 20165
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: unable to discover open pages
  (Driver info: chromedriver=2.3,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.55 seconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'DESKTOP-9KFNBI3', ip: '192.168.0.104', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: driver.version: ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$24(ProtocolHandshake.java:359)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:362)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:136)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:217)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:140)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at newPackage.MyClass.main(MyClass.java:10)

共有3个答案

薛保臣
2023-03-14

我在你的代码中没有看到任何这样的错误。

您观察到的错误是由于版本控制不匹配造成的。您使用的是Selenium v3.6.0和chromedriver v2.3(非常旧),不兼容。

由于您正在使用最新版本的Selenium,即v3.6.0,我建议您使用chromedriver v2.32或最新的chromedriver v2.33

郑旭
2023-03-14

经过一些实验,我同意确保chromedriver可执行文件在您的路径上。您可能会发现系统属性的设置可能是不必要的。

周奇文
2023-03-14

问题可能是由于您的chrome驱动程序造成的
获取chrome驱动程序并在代码中设置路径,然后重试代码。如果你能克服这个问题,请告诉我。

使用以下链接从google获取最新版本的chrome驱动程序(2.33)
:https://sites.google.com/a/chromium.org/chromedriver/downloads
[或]
从Selenium下载:http://www.seleniumhq.org/download/

 类似资料:
  • 导入init.constants; 公共类TestSelenium{ } WebDriver-3.0

  • 我面临下面的问题,而运行脚本在chrome headless上使用Selenium java和Windows OS。URL未打开,我的应用程序URL的页面标题为空。..chrome驱动程序版本2.33,chrome浏览器62。..我使用下面的代码 是因为应用程序的URL不支持无头模式…没有得到任何异常…

  • 我想问一下在selenium测试执行期间如何打开Chrome开发人员控制台。目前,当测试正在执行时,我手动点击F12打开控制台,测试立即停止响应,一段时间后失败。 有人能告诉我如何在开发人员控制台打开的情况下启动测试,以便捕获/观察测试执行期间发生的控制台错误吗。

  • 我正在使用selenium使用chrome浏览器来自动化网页,但是chrome浏览器没有启动,它在地址栏中显示“数据:;”而没有加载任何页面。 selenium: selenium-服务器-独立-3.0.0-beta2,也尝试了2.53 Chrome驱动程序:2.23(http://chromedriver.storage.googleapis.com/index.html?path=2.23/)

  • 我的chrome浏览器在Selenium Webdriver中没有打开。根据兼容性,我已经下载了所有的东西,如chrome driver,Selenium jars和chrome。我使用的是Intellij IDEA IDE。代码和版本细节如下- 版本: Chrome:89.0.4389.90 IDE:IntelliJ IDE:203.7148.57 Chrome驱动程序:https://chro

  • 我最近一直在使用Selenium WebDriver。我还专门与ChromeDriver一起工作。每当我打开一个新的chrome窗口(driver.get(url)),chrome就会以完全默认的状态启动,而不是从dock打开一个新窗口(我在运行OS X Yosemite的macbook上)。有办法解决这个问题吗?还是这只是一种既定的行为?