How to change web browser from Firefox to Chrome / Opera / IE / Safari in selenium webdriver?

How to change the browser from Firefox to Chrome / Opera / IE running in selenium webdriver? Please follow the steps as well as the code snippet.

Please answer if you have an answer to any of the browsers mentioned above.

I read a lot about this, but I could not properly link it.

+7
source share
1 answer

First of all, you need to import the appropriate drivers into the project / class.

as

import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.ie.InternetExplorerDriver; 

and etc.

You need to create new Webdrivers for the browser you need.

as

 WebDriver driver = new FirefoxDriver(); WebDriver driver = new InternetExplorerDriver(); WebDriver driver = new ChromerDriver(); 

etc. for each browser.

Note: It is difficult to use different browsers / drivers in one test. Either you can use similar tests for each browser and support the test suite (i.e. use one driver and import in the test and support the same test for other browsers), or you can use some configuration files or Excel to choose which browser you want a test to run. You could study http://htmlunit.sourceforge.net/ for headless testing.

And information about OperaDriver can be found here: - https://github.com/operasoftware/operadriver/

+11
source

All Articles