【问题标题】:Selenium for Edge in Build 18362 or higherSelenium for Edge 在 Build 18362 或更高版本中
【发布时间】:2020-04-13 06:16:16
【问题描述】:

我在使用 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/");

【问题讨论】:

  • 下一步是找到它的安装位置...但一般来说,如果您可以将驱动程序可执行文件包含在您的存储库中,那么您将总是知道在哪里你可以找到司机。您是在本地运行代码还是在某种管道中运行代码?

标签: selenium selenium-webdriver webdriver microsoft-edge selenium-edgedriver


【解决方案1】:

New in EdgeHTML 18

EdgeHTML 18 包括从Windows 10 October 2018 Update(10/2018,内部版本 17763)开始在当前版本的 Microsoft Edge 平台中提供的以下新功能和更新功能。有关特定 Windows Insider 预览版的更改,请参阅 Microsoft Edge ChangelogWhat's New in EdgeHTML


根据微软博客Enhancing automated testing in Microsoft Edge with new WebDriver capabilities, W3C protocol support, and automatic updates

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() 了。


参考

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

【讨论】:

  • 需要注意的重要一点:确保安装 Selenium.WebDriver.MicrosoftDriver 包。我已按照您概述的步骤进行操作(我在 Microsoft 的网站上找到了这些步骤),但我仍然收到错误消息,称连接已被强制关闭。删除包解决了错误。
  • @MarcLevesque 你的评论应该对社区很有帮助。随意编辑答案并添加相关信息。
【解决方案2】:

您可以从以下文件夹中找到 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);  
    }    
}

【讨论】:

    【解决方案3】:
     String windir = System.getenv("windir");
     String edgeDriverPath = windir + "\\SysWOW64\\MicrosoftWebDriver.exe";  
     System.setProperty("webdriver.edge.driver", edgeDriverPath); 
     driver = new EdgeDriver();
    

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

    【讨论】:

    • 好的-我想我知道我做错了什么。我猜从 Windows 10 1903 开始​​,Edge Web 驱动程序就不必具有 SystemsetProperty。所以这就是我现在拥有的并且能够毫无问题地运行
    • WebDriver driverEdge = new EdgeDriver(); driverEdge.get("google.com");
    • 哦,我不知道... System.setProperty 将用于 Java 运行时,但您是说不需要该行?
    • 正确。我只需要对 Chrome、Firefox 和 IE11 使用 System.setProperty。
    • 感谢您让我知道...目前没有可用于测试的 Win10 机器。
    猜你喜欢
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多