ChromeDriver: Custom Chrome Executable Path

南楼画角 提交于 2019-12-19 04:06:09

问题


I'm using the portable version of Google Chrome.

Since WebDriver expects the default installation path, it does not find the portable one which obviously is at another location:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 11.13 seconds
Build info: version: '2.35.0', revision: '8df0c6b', time: '2013-08-12 15:43:19'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
Driver info: org.openqa.selenium.chrome.ChromeDriver

How do I set a custom path to the chrome.exe file?


回答1:


Nevermind, I found the answer myself:

ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/chrome/binary");

ChromeDriver driver = new ChromeDriver(options);

Chromedriver docs




回答2:


Python version:

chromedriver = "/path/to/chromedriver"
options = Options()
options.binary_location = '/path/to/chrome'
driver = webdriver.Chrome(chromedriver, chrome_options=options)


来源:https://stackoverflow.com/questions/23978464/chromedriver-custom-chrome-executable-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!