Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How to change browser from firefox to Chrome/Opera/IE working in selenium webdriver? Please guide in steps and also with the code snippet.

Please reply if you have answer for any of the browsers mentioned above.

I read out a lot on this but could not link it properly.

like image 443
pranky301 Avatar asked Aug 12 '12 07:08

pranky301


People also ask

How do I change webbrowser in Selenium?

We can switch different browser tabs using Selenium webdriver in Python using the method switch_to. window. By default, the webdriver has access to the parent window. Once another browser tab is opened, the switch_to.

Does Selenium support Opera browser?

> Selenium WebDriver supports Firefox, Chrome, Internet Explorer, Safari, Edge and Opera Browsers.

What is WebDriverManager ChromeDriver () setup ()?

WebDriverManager is an open-source Java library that carries out the management (i.e., download, setup, and maintenance) of the drivers required by Selenium WebDriver (e.g., chromedriver, geckodriver, msedgedriver, etc.) in a fully automated manner.


1 Answers

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

like

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

etc.

The you need to create new Webdrivers for the broswer you need.

like

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

etc for each browser.

NOTE: It is tough to use different browsers/drivers in a single test. Either you may use similar tests for each browser and maintain a test-suite (i.e. use one driver and import in a test and maintain similar test for other browsers) or you can use some config files or excel to pick up which browser you want the test to run. You might like to explore http://htmlunit.sourceforge.net/ for headless testing.

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

like image 164
some_other_guy Avatar answered Nov 15 '22 16:11

some_other_guy