Selenium calls Chrome, Firefox, IE, seleniumchrome

Source: Internet
Author: User

Selenium calls Chrome, Firefox, IE, seleniumchrome

In the C # environment, you can use Selenium to call different browsers as follows:

 1 IWebDriver driver = null; 2 string Browser =null; 3 if (Browser.Equals("IE")) 4 { 5   InternetExplorerOptions options = new InternetExplorerOptions(); 6   options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; 7   driver = new InternetExplorerDriver(options); 8  9 }10 else if (Browser.Equals("Chrome".ToUpper()))11 {12   driver = new ChromeDriver();13 }14 else15 {16   driver = new FirefoxDriver();17 }

Note:

1. The iedriverserver.exe file must be stored in the bin \ Debug or bin \ releasedirectory of the project when using IE browser.

Use nugetto obtain iedriverserver.exe: Install-Package WebDriver. IEDriverServer. win32

2. When using IE, remove the protection mode of the browser and add the following code.

InternetExplorerOptions options = new InternetExplorerOptions();options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

3. When using the Chrome browser, you must download the chromedriver.exe file in the bin \ Debug or bin \ releasedirectory of the project.

Use nugetto obtain chromedriver.exe: Install-Package Selenium. WebDriver. ChromeDriver

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.