【问题标题】:Java/Selenium: Simple program to open Edge fails (dependency issue?)Java/Selenium:打开 Edge 的简单程序失败(依赖问题?)
【发布时间】:2017-08-09 09:27:26
【问题描述】:

我刚开始使用 Selenium,我刚开始使用一个简单的脚本来打开 Edge 并转到 google:

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;

public class openEdge
{
   public static void main(String[] args)
  {
    System.setProperty("webdriver.edge.driver","E:\\Program Files 
    (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe");

    WebDriver driver = new EdgeDriver();
    System.out.println("here");
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get("https://www.google.com");
  }
}

当我运行它时,Edge 成功打开,但在创建 Webdriver 实例后似乎失败(即不打印“here”)。这是我得到的错误:

Exception in thread "main" org.openqa.selenium.NoSuchSessionException: null (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 358 milliseconds

接着是构建和系统信息,然后是 EdgeDriver 的驱动程序信息的长列表。我已经向 selenium 客户端和服务器 jar 添加了依赖项。任何帮助将不胜感激!

编辑:根据要求构建、系统和驱动程序信息。我现在注意到构建信息都是未知的,我猜这与它有关。我会尝试重新下载我所有的依赖项:

Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'myname', ip: 'myip', os.name: 'Windows 10', 
os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: EdgeDriver
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:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
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$22(ProtocolHandshake.java:365)
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:368)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:150)
at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:139)
at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:96)
at openEdge.openEdge.main(openEdge.java:16)

【问题讨论】:

  • IMO 为进一步分析,我们需要从您的控制台查看确切的 Build and system info then a long list of driver info for the EdgeDriver。

标签: java selenium


【解决方案1】:

下载 selenium webdriver 的最新 jars(selenium 服务端和 selenium 客户端绑定)。

http://docs.seleniumhq.org/download/

从以下路径下载最新的 edge .exe

https://download.microsoft.com/download/3/4/2/342316D7-EBE0-4F10-ABA2-AE8E0CDF36DD/MicrosoftWebDriver.exe

这段代码在我这边运行良好:-

System.setProperty("webdriver.edge.driver","D:\\Workspace\\FluentWaitTest\\src\\lib\\MicrosoftWebDriver.exe");

WebDriver driver = new EdgeDriver();
System.out.println("here");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.google.com");
  driver.findElement(By.id("lst-ib")).sendKeys("selenium");
  driver.manage().window().maximize();
  List<WebElement> print = driver.findElements(By.xpath("//div[@class='sbqs_c']"));
  System.out.println(print.size());
  for ( WebElement we: print) { 
        System.out.println(we.getText());
    }
  }

【讨论】:

    【解决方案2】:

    我最终为我的操作系统版本安装了错误的 WebDriver 版本(从教程中的链接获得...)。为我的构建安装了正确的,现在它工作正常。感谢您的帮助。

    【讨论】:

      【解决方案3】:

      MicroSoftWebDriver.exe(用于 Edge)应该与您正在测试的 Microsoft Edge 版本兼容。

      之前,上述答案都是正确的,需要我们根据相应的操作系统版本手动下载。但是,从去年开始,Microsoft 边缘驱动程序现在作为操作系统的一部分分发

      要遵循的步骤:-

      1. 转到设置
      2. 点击“添加或删除程序”以登陆应用和功能
      3. 点击“管理可选功能”
      4. 点击按钮 - “添加功能”
      5. 搜索 Microsoft Web 驱动程序并安装

      现在,因为在我们的 selenium 测试中,我们需要参考“.exe”文件的确切位置。

      1. 转到“C:\Windows\SysWOW64”文件夹位置
      2. 你会发现“MicrosoftWebDriver.exe”

      您可以将其复制到您引用浏览器驱动程序的位置。

      如果您有兴趣了解详情,请参阅此链接 - https://blogs.windows.com/msedgedev/2018/06/14/webdriver-w3c-recommendation-feature-on-demand/#Rg8g2hRfjBQQVRXy.97

      【讨论】:

        猜你喜欢
        • 2017-05-01
        • 2010-11-14
        • 1970-01-01
        • 2015-10-12
        • 1970-01-01
        • 2021-06-21
        • 2016-05-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多