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

前端 未结 4 610
有刺的猬
有刺的猬 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/");
         }
    }
    

提交回复
热议问题