[英]webDriverException "selenium.common.exceptions.WebDriverException: Message: Service ./webdrivers/geckodriver unexpectedly exited. Status code was: 1"
I am running a simple python based selenium webdriver script for geckodriver我正在为 geckodriver 运行一个简单的基于 python 的 selenium webdriver 脚本
from selenium import webdriver
geckodriver_path = "./webdrivers/geckodriver"
driver = webdriver.Firefox(executable_path=geckodriver_path)
driver.get("https://dev.to")
driver.find_element_by_id("nav-search").send_keys("Selenium")
after execution showing Warning message along with Exception执行后显示警告消息和异常
/<path>/demo.py:3: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Firefox(executable_path=geckodriver_path)
And the exception is例外是
selenium.common.exceptions.WebDriverException: Message: Service ./webdrivers/geckodriver unexpectedly exited. Status code was: 1
The environment which is being used正在使用的环境
python(3.9.2)蟒蛇(3.9.2)
selenium(4.1.0)硒(4.1.0)
geckodriver(0.24.0)壁虎驱动程序(0.24.0)
firefox(87.0 64-bit)火狐(87.0 64 位)
Output of geckodriver.log geckodriver.log 的 Output
error: Found argument '--websocket-port' which wasn't expected, or isn't valid in this context
USAGE:
geckodriver [FLAGS] [OPTIONS]
For more information try --help
In Selenium after version 4, it's recommended to use Services, still don't know why, but if someone will find, it would be great to know.在Selenium版本4之后,推荐使用Services,还是不知道为什么,但是如果有人会发现,那就太好了。
To resolve you issue you could try this:要解决您的问题,您可以尝试以下操作:
from selenium.webdriver.firefox.service import Service as FXService
from selenium.webdriver import Firefox
search_by = 'xpath'
search_path = "//div[@id='header-search']/form/div/div/input"
driver_path = './webdrivers/geckodriver'
driver = Firefox(service=FXService(driver_path))
driver.get("https://dev.to")
driver.find_element('xpath', div_path).send_keys("Selenium")
Hope this will be helpful!希望这会有所帮助!
It works after giving absolute path for variable geckodriver_path, also update geckodriver version to latest one.它在为变量 geckodriver_path 提供绝对路径后工作,还将 geckodriver 版本更新为最新版本。 (currently it is 0.30.0 which is compatible with firefox 87.0 64-bit )
(目前是 0.30.0 兼容 firefox 87.0 64-bit )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.