How to remove the infobar “Microsoft Edge is being controlled by automated test software” in selenium test

前端 未结 4 611
有刺的猬
有刺的猬 2021-01-27 00:30

We are using selenium to run test against \"Chromium based Edge\". \"The Chromium Edge\" is downloaded from https://www.microsoftedgeinsider.com/en-us/download and the version i

4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-27 00:45

    @Zhi Lv - MSFT

    What is the browser you are launching? Chrome or Chromium-Edge? I am using selenium java code, if I run the similar java code as below, it will fail with error The path to the driver executable must be set by the webdriver.chrome.driver system property;

    System.setProperty("webdriver.edge.driver", "C:\\SeleniumPlus\\extra\\msedgedriver.exe");
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
    chromeOptions.setExperimentalOption("useAutomationExtension", false);
    chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    WebDriver driver = new ChromeDriver(chromeOptions);
    driver.get("http://www.google.com");
    

    If I create an edge capabilities and merge the ChromeOption into it, I can see that "Chromium-Edge" gets started without the "infobar", but it just gets stuck there and fails with an error unknown error: unrecognized Chrome version: Edg/80.0.361.5

    System.setProperty("webdriver.edge.driver", "C:\\SeleniumPlus\\extra\\msedgedriver.exe");
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
    chromeOptions.setExperimentalOption("useAutomationExtension", false);
    chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    DesiredCapabilities m_capability = DesiredCapabilities.edge();
    m_capability.merge(chromeOptions);
    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), m_capability);
    driver.get("http://www.google.com");
    

    From the "selenium server" console, I can see, the "browserName" is "chrome", I guess that is the reason why chrome's options is working to get rid of the "infobar"

    15:37:55.502 INFO [ActiveSessionFactory.apply] - Capabilities are: {
      "browserName": "chrome",
      "goog:chromeOptions": {
        "args": [
        ],
        "binary": "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe",
        "excludeSwitches": [
          "enable-automation"
        ],
        "extensions": [
        ],
        "useAutomationExtension": false
      },
      "platform": "WINDOWS",
      "version": ""
    }
    

    If I set the "browserName" to "MicrosoftEdge" after merging the chrome's options as below, it can get the "Chromium-Edge" started, but the chrome's options do not work any more, which means the "infobar" is still there.

    m_capability.merge(chromeOptions);
    m_capability.setCapability(CapabilityType.BROWSER_NAME, BrowserType.EDGE);
    

提交回复
热议问题