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

前端 未结 4 609
有刺的猬
有刺的猬 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条回答
  • 2021-01-27 00:37

    You could refer to the following code (C# code) to set the chrome options and remove the infobar.

            var edgechromiumService = ChromeDriverService.CreateDefaultService(@"E:\edgedriver_win64", "msedgedriver.exe");
            // user need to pass the driver path here....
            ChromeOptions edgechromeOptions = new ChromeOptions
            {
                BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe",
            };
    
            edgechromeOptions.AddAdditionalCapability("useAutomationExtension", false);
            edgechromeOptions.AddExcludedArgument("enable-automation"); 
    
            using (IWebDriver driver = new ChromeDriver(edgechromiumService, edgechromeOptions))
            {
                driver.Navigate().GoToUrl("https://www.bing.com/");
                Console.WriteLine(driver.Title.ToString());
    
                //driver.Close();
                Console.ReadKey();
            }
    

    The result like this:

    For Java applications, please try to use the following code:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions; 
    import org.openqa.selenium.edge.EdgeOptions;    
    import java.util.*;  
    public class Edgeauto {
        public static void main(String[] args) { 
            System.setProperty("webdriver.chrome.driver", "your\\path\\to\\edge\\webdriver\\msedgedriver.exe");
            ChromeOptionschromeOptions = 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"));
    
            EdgeOptions edgeOptions = new EdgeOptions().merge(chromeOptions);
            WebDriver driver = new ChromeDriver(edgeOptions);
            driver.get("https://www.google.com/");
         }
    }
    
    0 讨论(0)
  • 2021-01-27 00:38

    You saw it right.

    As per the article Microsoft’s Edge Chromium browser will launch on January 15th with a new logo Microsoft is planning to release its Edge Chromium browser on January 15th 2020 with availability for Windows 10, Windows 7, Windows 8, and macOS. This came just after Microsoft released the beta version of Edge.

    Now, this Beta also means that Microsoft is edging closer to the release stage for its Chromium browser. Microsoft first released its Canary and Developer builds of Edge back in April, and the company has spent the past four months working alongside Google to improve Chromium for Windows. That work also involved Microsoft getting used to the cadence of delivering a Chromium browser.

    Hence adding the ExperimentalOption you see the Microsoft’s Edge Chromium browser almost like a Chromium / Chrome browser.

    0 讨论(0)
  • 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);
    
    0 讨论(0)
  • 2021-01-27 00:50

    I think that I can explain the all the confusions (perhaps for myself

    0 讨论(0)
提交回复
热议问题