Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run two different versions of chrome using selenium (Python)

I have a scenario to run different versions of chrome in windows (for now let us consider only two). I have found the following way to run an instance of chrome:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
driver = webdriver.Chrome(
    chrome_options=chrome_options
)

I have default chrome and another version (located in Downloads directory). How do I run any desired version?

EDIT:

I have some blogs written here and here. Hope this helps someone.

like image 967
Nabin Avatar asked Jul 02 '17 04:07

Nabin


People also ask

Can you have 2 versions of Chrome?

Update October 13, 2020: Chrome Beta and Chrome Dev can now be installed side-by-side on Mac as well. Side-by-side Chrome installation is available on Windows, Mac, Android, and Linux.

How can we launch different browsers in Selenium Webdriver?

We can launch Chrome browser via Selenium. Java JDK, Eclipse and Selenium webdriver should be installed in the system before Chrome browser is launch. Navigate to the link: https://chromedriver.chromium.org/downloads. Select the Chrome driver link which matches with the Chrome browser in our system.


1 Answers

One way is to define the location in the capabilities with the Options class:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.binary_location = r'C:/chromium-48/chrome.exe'
driver = webdriver.Chrome(chrome_options=options)

or with DesiredCapabilities:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

capa = DesiredCapabilities.CHROME;
capa['chromeOptions'] = {
  'binary': r'C:/chromium-48/chrome.exe',
  'args': []
}

driver = webdriver.Chrome(desired_capabilities=capa)

But if you are looking for a scalable solution, then you should setup a grid with the different versions:

  • Start the hub:
java -jar selenium-server-standalone-2.53.1.jar -role hub -host 0.0.0.0 -port 4444
  • Start a node for version 48:
java -jar selenium-server-standalone-2.53.1.jar 
 -role node 
 -hub http://localhost:4444/grid/register
 -browser platform=WINDOWS,browserName=chrome,version=48,chrome_binary="C:/chromium-48/chrome.exe"
  • Start a node for version 54:
java -jar selenium-server-standalone-2.53.1.jar 
 -role node 
 -hub http://localhost:4444/grid/register
 -browser platform=WINDOWS,browserName=chrome,version=54,chrome_binary="C:/chromium-54/chrome.exe"

You can then choose the version directly in the capabilities:

from selenium import webdriver
capa = {'browserName': 'chrome', 'version': '48', 'platform': 'ANY'}
driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=capa)
like image 118
Florent B. Avatar answered Sep 21 '22 10:09

Florent B.