我想學習Python的Webdriver,使用Python的基本理解,以及對Selenium和JAVA的更廣泛的理解。我遵循指南發現here。我的代碼:Python Selenium Webdriver不會運行,即使正確的PATH和腳本寫作指示
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.google.com")
assert "Google" in driver.title
sb = driver.find_element_by_name(lst-ib)
sb.clear()
sb.send_keys("Youtube")
sb.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
現在,運行這PyCharm將返回:
C:\Users\mbrenn002c\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/mbrenn002c/PycharmProjects/PyDriver/Webdriver.py
Traceback (most recent call last):
File "C:/Users/mbrenn002c/PycharmProjects/PyDriver/Webdriver.py", line 5, in <module>
driver = webdriver.Firefox()
File "C:\Users\mbrenn002c\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__
keep_alive=True)
File "C:\Users\mbrenn002c\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\mbrenn002c\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Users\mbrenn002c\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Users\mbrenn002c\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
Process finished with exit code 1
我的PIP封裝:硒; beautifulsoup4。
我的路徑如下這樣:
%USERPROFILE%\AppData\Local\Mirosoft\WindowsApps;C:\Users\myuser\AppData\Programs\Python;C:\Pythone34;C:\Users\myuser\Desktop\File transfer\Eclipse Items\geckodrver.exe
我的主要問題是;我究竟做錯了什麼?據我所知,我已經正確地遵循了一切,這段代碼應該打開geckodriver並按照列出的方式工作。它甚至不會運行selenium獨立服務器運行webdriver。
我試過用相同的點子和代碼我QPython客戶端上我的Android手機,這回一些回調在控制檯運行它,這個到底:
Exception AttributeError: "'Service' object has no attribute 'log_file'" in <bound method Service.__del__ of <seleniumwebdriver.firefox.service.Service object at 0xf5e709f0>> ignored
它可能值得注意的是我的手機沒有Rooted,而我所做的只是保存這一個腳本,並且安裝了Selenium和beautifulsoup4。
我沒有從手機發布完整的回覆日誌,因爲它的長度和可能與問題缺乏相關性。如果需要,我可以發佈它,或者詳細闡述/擴展任何問題的部分。 –