Python – Opening multiple tabs using Selenium
Testing is an important concept in software methodology. Software is said to be effective and efficient only if it is bug-free. Testing can be done manually and also via automation. In Python, selenium is used to do automated testing. The selenium package is available, and they are much helpful to automate web browser interaction from Python.
In this article, we are going to discuss how to open multiple tabs using selenium.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
pip install selenium
Selenium Driver requirements for different browsers :
Each browser is different and similarly, they require different selenium webdrivers.
Popular browsers like Chrome, Firefox etc., and their webdriver download path is given below
Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Firefox: https://github.com/mozilla/geckodriver/releases Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10
To begin with, let us see a normal example of opening a firefox browser
- We need Geckodriver to open firefox browser. It can be downloaded from https://github.com/mozilla/geckodriver/releases. It has to be set in “Path” variable in windows and also in Linux and Mac, in respective locations it has to be set.
- Open a new Firefox browser from Python.
- Then load the page at the given valid URL.
On execution of the code, we can see the actions that is shown below:
Ways to open multiple tabs using Selenium:
- After specifying either Firefox/Chrome driver for selenium, first, we need to open a webpage
- Then we need to switch to that tab and for that tab can give any valid URL.
The very same above program can be run by using the chrome driver as well. Chrome driver is version specific and hence respective version to your chrome browser, we need to download
A small change in the above code is instead of “webdriver.Firefox()” , we should have webdriver.Chrome()
Let us see how to open 3 tabs using chrome driver now
On execution of the scripts, we can see:
Let us check how to specify different drivers by taking browser name as input and open multiple tabs
Selenium testing is getting applied in all software industries. It is quicker and efficient. Manual errors also got overcome by means of selenium testing. As everywhere automation is happening, testing also getting done in automated ways only nowadays. Opening multiple tabs for checking different functionalities is a common task.