Getting Chrome to launch via Selenium

假如想象 提交于 2019-12-18 12:17:32

问题


Hi all I'm very new to this and am having issues getting an instance of a Chrome browser from selenium in python. I'm using Windows 8. I have downloaded the chromedriver binary and added it to my path but I get the following error in Python:

selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.   

This error occurs for the following line:

driver = webdriver.Chrome(executable_path='path\to\chromedriver_win32_2.0')  

Any help is greatly appreciated. Thank you.


回答1:


Two ways to set it, you somehow mixed up.

  • Put the chromedriver.exe's path into PATH (on Windows), so your PATH setting is correct, but you need to call the default constructor.

    driver = webdriver.Chrome()

  • Specify the path in webdriver.Chrome(executable_path='some path'). Here you need the full path to the executable, not the directory.

    webdriver.Chrome(executable_path=r'C:\Users\HaranKumar\Downloads\chromedriver_win32_2.0\chromedriver.exe')

Choose either one you want.




回答2:


Assuming that your path is correct, make sure that you include the chromedriver itself: chromedriver.exe




回答3:


I used the following and it worked! Thanks!

driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe')
#put your own path between the ''



回答4:


Even if you have chromedriver.exe in the PATH, its necessary to have chromedriver.exe in the folder where your executable scripts are present(atleast so is the case when it comes to python scripts)




回答5:


Update 2016

The following solution works for me, with WebDriver 3.0.1, Chrome Driver 2.25.426923, Window 7

    System.setProperty("webdriver.chrome.driver","D:\\workspace\\chromedriver.exe");
    WebDriver driver;
    driver = new ChromeDriver();

*Note:

  • Chrome Driver
  • See also: http://www.frontendtest.org/blog/path-executable-chrome/


来源:https://stackoverflow.com/questions/17436598/getting-chrome-to-launch-via-selenium

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