How to Use Different Browser Types in Selenium and Browserist#
If you need to automate web scraping or test flows with different browsers – for example, Firefox, Edge, or Chrome – Selenium and Browserist do it differently.
Basic Usage#
With Selenium#
If you want to use Chrome for browser automation with Selenium, here's how to initiate a session:
Python | |
---|---|
1 2 3 4 5 6 7 |
|
If you want to use Firefox, just replace webdriver.Chrome()
with webdriver.Firefox()
. Or use webdriver.Edge()
for Edge.
With Browserist#
With Browserist, you can often achieve the same thing, but with less and more readable code:
Python | |
---|---|
1 2 3 4 5 |
|
For Firefox or Edge, just replace BrowserType.CHROME
with BrowserType.FIREFOX
or BrowserType.EDGE
, respectively.
Multiple Browsers in a Session#
Let's imagine another example where we want to do the same task, but with different browser types.
With Browserist#
Because the configuration class is separate from the web driver and consistent across browser types, Browserist often scales with less code compared to Selenium:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 |
|
With Selenium#
With Selenium, the above example could be rewritten like this:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Selenium Mixed with Browserist#
Alternatively, you can mix Selenium with Browserist:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 |
|