0x1 什么问题
一般我们使用linux操作系统,会把chromedriver或者chrome浏览器放入环境变量,那么用户selenium调用server的时候无需指定任何路径。但是有时候我们本地win或者mac做selenium server绿色版,不想把浏览器/chromedriver放入环境变量中,那应该怎么办呢?
0x2 指定路径
这里以chrome浏览器为例,客户端调用的时候是可以传入chrome路径的,这样的话,服务端浏览器不必强制放入环境变量中
#!/bin/python3
# -*- coding: utf-8 -*-
# mac下: 使用/Users/yuc/Desktop/123456/chrome/google/Chromium.app,这个路径在macos是能够打开chrome浏览器的,但是selenium必须要定位到后面的Chromium
# win下: 路径需要使用\\
# 类unix下: 最好加上--no-sandbox,默认root是不允许启动chrome的
import selenium
from selenium import webdriver
#bpath = '/usr/bin/google-chrome'
#bpath = '/Users/yuc/Desktop/123456/chrome/google/Chromium.app/Contents/MacOS/Chromium'
#bpath = '/Users/yuc/Desktop/123456/packagefiles/mac/chrome/Chromium.app/Contents/MacOS/Chromium'
#bpath = 'C:\\App\\code\\bi-bins\\packagefiles\\win\\chrome\\chrome.exe'
chrome_options = webdriver.chrome.options.Options()
#url = 'http://192.168.3.151:4444/wd/hub'
#url = 'http://192.168.13.60:4444/wd/hub'
url = 'http://192.168.3.151:10444/wd/hub'
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--lang=zh_CN')
#chrome_options.binary_location = bpath
print (chrome_options.binary_location)
dc = ""
driver = webdriver.chrome.webdriver.RemoteWebDriver(command_executor=url, desired_capabilities=chrome_options.to_capabilities())
#driver = webdriver.remote.webdriver.WebDriver(command_executor=url, desired_capabilities=chrome_options.to_capabilities())
driver.get('https://dev.succez.com')
print(driver.page_source)
driver.quit()