1

我在使用 Edge 的 webdriver 时遇到了困难。我知道驱动程序是通过以下命令安装的:

DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0

但是这之后的下一步是什么?到目前为止,这是我在 Java 中的代码:

System.setProperty("webdriver.edge.driver", "[I don't know the path of the install]");
@SuppressWarnings("deprecation")
WebDriver driverEdge = new EdgeDriver(options);
driverEdge.get("https://www.google.com/");
4

3 回答 3

0
 String windir = System.getenv("windir");
 String edgeDriverPath = windir + "\\SysWOW64\\MicrosoftWebDriver.exe";  
 System.setProperty("webdriver.edge.driver", edgeDriverPath); 
 driver = new EdgeDriver();

这假定为 64 位,我还没有实际测试过,所以请让我知道它是否有效。对于 32 位,我相信该目录将由“System32”而不是“SysWOW64”。

于 2019-12-20T19:46:01.210 回答
0

EdgeHTML 18 中的新功能

EdgeHTML 18 包括 Microsoft Edge 平台的当前版本中提供的以下新功能和更新功能,截至2018 年 10 月 10 日的 Windows 更新(10/2018,内部版本 17763)。有关特定Windows Insider Preview 版本的更改,请参阅Microsoft Edge 更改日志EdgeHTML 中的新增功能


根据 Microsoft 博客使用新的 WebDriver 功能、W3C 协议支持和自动更新增强 Microsoft Edge 中的自动化测试

WebDriver 需要与您正在测试的 Microsoft Edge 版本相匹配,这在历史上需要手动将 WebDriver 的独立下载与您设备上的适当 Windows 版本进行匹配。

所以现在 WebDriver 成为Windows Feature on Demand (FoD),它确保它始终自动更新,并且还支持一些获取 Microsoft WebDriver 的新方法。

脚步

  • 启用将安装适当版本的 WebDriver 的开发人员模式。

    Open Settings app > Go to Update & Security > For Developer and then select "Developer Mode".
    
  • 您还可以通过以下两种方式之一安装独立版本的 WebDriver:

    • 从开始搜索“管理可选功能”,然后选择“添加功能”、“WebDriver”。
    • 通过在提升的命令提示符下运行以下命令来通过 DISM 安装:

      DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
      

结论

使用提升的命令提示符安装MicrosoftWebDriver后,它将自动更新,您不必再提及MicrosoftWebDriver二进制文件的绝对路径System.setProperty()


参考

您可以在以下位置找到详细讨论:

于 2020-01-03T21:48:53.453 回答
0

您可以从以下文件夹中找到 Microsoft Edge WebDriver:

C:\\Windows\\WinSxS\\amd64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_c52dd23839475f5b\\MicrosoftWebDriver.exe

C:\\Windows\\System32\\MicrosoftWebDriver.exe

C:\\Windows\\SysWOW64\\MicrosoftWebDriver.exe

C:\\Windows\\WinSxS\\wow64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_cf827c8a6da82156\\MicrosoftWebDriver.exe

然后,参考以下代码将 Microsoft Edge WebDriver 与 Java 结合使用:

package seleniumtest; 

import org.openqa.selenium.By;
import org.openqa.selenium.Keys; 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class testsample {

    public static void main(String[] args) { 

         //String windir = System.getenv("windir");
         //String edgeDriverPath = windir + "\\SysWOW64\\MicrosoftWebDriver.exe";  

         //String edgeDriverPath = "C:\\Windows\\WinSxS\\amd64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_c52dd23839475f5b\\MicrosoftWebDriver.exe";
         //String edgeDriverPath = "C:\\Windows\\System32\\MicrosoftWebDriver.exe";
         //String edgeDriverPath = "C:\\Windows\\SysWOW64\\MicrosoftWebDriver.exe";

         String edgeDriverPath = "C:\\Windows\\WinSxS\\wow64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_cf827c8a6da82156\\MicrosoftWebDriver.exe";

         System.setProperty("webdriver.edge.driver", edgeDriverPath); 
         WebDriver driver = new EdgeDriver();

         //replace the URL of the web page here..
         driver.get("https://www.bing.com");
         //wait page load success.
         WebDriverWait wait = new WebDriverWait(driver, 5);
         wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("sb_form_q")));

         //find the element from the web page.
         WebElement element = driver.findElement(By.id("sb_form_q"));
         //enter value and search
         element.sendKeys("web driver");
         element.sendKeys(Keys.ENTER);  
    }    
}
于 2019-12-23T06:57:26.373 回答