- Selenium Webdriver Tutorial
- Home
- Introduction
- Installation
- Browser Navigation
- Identify Single Element
- Identify Multiple Elements
- Explicit and Implicit Wait
- Pop-ups
- Backward and Forward Navigation
- Cookies
- Exceptions
- Action Class
- Create a Basic Test
- Forms
- Drag and Drop
- Windows
- Alerts
- Handling Links
- Handling Edit Boxes
- Color Support
- Generating HTML Test Reports in Python
- Read/Write data from Excel
- Handling Checkboxes
- Executing Tests in Multiple Browsers
- Headless Execution
- Wait Support
- Select Support
- JavaScript Executor
- Chrome WebDriver Options
- Scroll Operations
- Capture Screenshots
- Right Click
- Double Click
- Selenium Webdriver Useful Resources
- Selenium WebDriver - Quick Guide
- Selenium WebDriver - Useful Resources
- Selenium WebDriver - Discussion
Executing Tests in Multiple Browsers
Selenium supports multiple browsers like Chrome, Firefox, Safari, IE, and so on. For running the tests in a particular browser we should have to download the executable file for that browser from the below link −
https://www.selenium.dev/downloads/
Once the link is launched, scroll down to the Browsers section. Under this, all the available browsers which support execution are listed. Click on the documentation link to download the corresponding executable file.
For example, to trigger the tests on Chrome, click on the documentation link. In the next page, the list of all the versions of chromedriver shall be available.
Click on a link to download the chromedriver.exe file which matches with our local Chrome browser version. On the following page, we shall be directed to the zip files available for download for the platforms Windows, Linux, and Mac.
Click on a link to download the chromedriver.exe file which matches with our local operating system. Once the download is done, unzip the file and save it within the project directory.
For example in our project, we have saved the chromedriver.exe file within the drivers folder. Then we have to specify the path of this file within the webdriver.Chrome(executable_path='< path of chromedriver >').
Code Implementation
The code implementation for supporting multiple browsers is as follows −
from selenium import webdriver driver = webdriver.Chrome(executable_path='../drivers/chromedriver') #implicit wait time driver.implicitly_wait(5) #url launch driver.get("https://www.tutorialspoint.com/index.htm") #get browse name l = driver.capabilities['browserName'] print('Browser name: ' + l) #driver quit driver.quit()
Output
The output shows the message - Process with exit code 0 meaning that the above Python code executed successfully. Also, the browser in which the test has executed - chrome gets printed in the console.
Similarly, if we want to execute the test in the Firefox browser (versions greater than 47), we have to use the geckodriver.exe file.
To Continue Learning Please Login
Login with Google