chromebook上的Selenium无法找到chromedriver



我制作了一个python脚本,在我的windows机器上使用selenium,现在我试图在我的chromebook上运行它,但是我无法解决如何为我的chromebook获得chromedriver。

下面是python代码:
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException  
warnings.filterwarnings("ignore", category=DeprecationWarning) 
options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
driver.get("https://google.com")

它在我的Windows机器上工作完美,因为我有chromedriver在我的。py文件的同一文件夹中。

,但当试图运行python3 MyFile.PY在终端在我的chromebook我收到这个:

FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

这里有谁知道我如何在我的chromebook上解决这个问题,我尝试下载linux的chromedriver并将它放在我的linux文件中一起白色MyFile.PY

使用selenium,您必须保持chromedriver.exe在路径中。您可以从https://chromedriver.chromium.org/downloads下载chromedriver并将文件放在与代码相同的文件夹中,或者您可以这样做:

driver = webdriver.Chrome(executable_path="path to the chromedriver", options=options)

我得到了相同的结果。我可以将chromedriver可执行文件安装到/usr/local/bin/中,然后在python中的chromedriver()的构造函数中命名它,并观察:

$ python3 test.py 
Start tests
/home/paul/scm/MyProj/test.py:30: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
Traceback (most recent call last):
File "/home/paul/scm/MyProj/test.py", line 30, in <module>
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
File "/home/paul/.local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/home/paul/.local/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__
super().__init__(
File "/home/paul/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 272, in __init__
self.start_session(capabilities, browser_profile)
File "/home/paul/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 364, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/paul/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "/home/paul/.local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
Stacktrace:
#0 0x5ad7cb440243 <unknown>
#1 0x5ad7cb2047a6 <unknown>
#2 0x5ad7cb22b94a <unknown>
#3 0x5ad7cb22949b <unknown>
#4 0x5ad7cb26b2a7 <unknown>
#5 0x5ad7cb26a8cf <unknown>
#6 0x5ad7cb261e53 <unknown>
#7 0x5ad7cb2349ea <unknown>
#8 0x5ad7cb235b2e <unknown>
#9 0x5ad7cb494d5e <unknown>
#10 0x5ad7cb498a80 <unknown>
#11 0x5ad7cb47a8b0 <unknown>
#12 0x5ad7cb499b63 <unknown>
#13 0x5ad7cb46bf75 <unknown>
#14 0x5ad7cb4bc998 <unknown>
#15 0x5ad7cb4bcb27 <unknown>
#16 0x5ad7cb4d7c23 <unknown>
#17 0x7d9d36ccfea7 start_thread

这可以在Mac上运行。Chrome有点奇怪&ChromeDriver在ChromeOS/Debian。这里有一个建议页面(https://chromedriver.chromium.org/getting-started/chromeos)和一个已发布的包装器类(https://chromium.googlesource.com/chromiumos/third_party/autotest/+/master/client/common_lib/cros/chromedriver.py),可能需要额外的检查。这些都感觉与标准的Selenium相差甚远

相关内容

  • 没有找到相关文章

最新更新