使用Selenium(Python)运行两个不同版本的chrome [英] Run two different versions of chrome using selenium (Python)
问题描述
我有一个在Windows中运行不同版本的chrome的方案(现在让我们考虑仅两个).我发现以下方法可以运行chrome实例:
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
)
我有默认的chrome和其他版本(位于下载"目录中).如何运行任何所需的版本?
I have default chrome and another version (located in Downloads directory). How do I run any desired version?
I have some blogs written here and here. Hope this helps someone.
推荐答案
一种方法是使用 Options
类在功能中定义位置:
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)
或具有 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:
- 启动中心:
java -jar selenium-server-standalone-2.53.1.jar -role hub -host 0.0.0.0 -port 4444
- 为版本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"
- 为版本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)
这篇关于使用Selenium(Python)运行两个不同版本的chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!