How to write Selenium Webdriver path address with python in Windows 10?

[亡魂溺海] 提交于 2019-12-12 04:19:14

问题


I'm making a simple web crawler using Python with selenium. (Running on PyCharm Window 10)

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get(http://www.python.org)

I tried various formats for the file Path but all of them seem to return error. What would be the correct format for the file Path? P.S. File address I copied off from File Explorer doesn't work either.


回答1:


Here is the Answer to your Question:

There is no Best Practice to copy/access the driver executable in the Automation Script but on my Windows 8 Pro machine with PyCharm IDE through Python 3.6.1, I explicitly mention the absolute path of the driver executable so that I can work with different versions of different driver executable as well as different Mozilla Firefox versions as follows:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
caps = DesiredCapabilities().FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get('https://stackoverflow.com')

Let me know if this Answers your Question.




回答2:


address should be within quotes as below.

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")


来源:https://stackoverflow.com/questions/45094157/how-to-write-selenium-webdriver-path-address-with-python-in-windows-10

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