我正在使用便携版Google Chrome。
由于WebDriver需要默认安装路径,因此它找不到显然位于其他位置的便携式路径:
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
如何设置chrome.exe
文件的自定义路径?
答案 0 :(得分:5)
没关系,我自己找到了答案:
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/chrome/binary");
ChromeDriver driver = new ChromeDriver(options);
答案 1 :(得分:0)
Python版本:
chromedriver = "/path/to/chromedriver"
options = Options()
options.binary_location = '/path/to/chrome'
driver = webdriver.Chrome(chromedriver, chrome_options=options)