Nab*_*bin 4 python selenium google-chrome
我有一个在 Windows 中运行不同版本 chrome 的场景(现在让我们只考虑两个)。我找到了以下运行 chrome 实例的方法:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
driver = webdriver.Chrome(
chrome_options=chrome_options
)
Run Code Online (Sandbox Code Playgroud)
我有默认的 chrome 和另一个版本(位于下载目录中)。我如何运行任何想要的版本?
一种方法是使用类定义功能中的位置Options:
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)
Run Code Online (Sandbox Code Playgroud)
或与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)
Run Code Online (Sandbox Code Playgroud)
但是如果你正在寻找一个可扩展的解决方案,那么你应该设置一个具有不同版本的网格:
java -jar selenium-server-standalone-2.53.1.jar -role hub -host 0.0.0.0 -port 4444
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
然后您可以直接在功能中选择版本:
from selenium import webdriver
capa = {'browserName': 'chrome', 'version': '48', 'platform': 'ANY'}
driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=capa)
Run Code Online (Sandbox Code Playgroud)