为什么我的webdriver.chrome()不工作



在我对这个问题的评论遭到抨击之前,我很清楚这可能是这个链接的重复,但提供的答案对我的代码实例没有帮助,即使在我的代码中应用了答案的调整版本之后也是如此。我已经研究了很多答案,包括在我的设备中安装Chromedriver,但都无济于事。

我的代码如下:

from selenium import webdriver
import time
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(executable_path = r'C:UsersuserDownloadschromedriver_win32')
driver.get('http://codepad.org')
text_area = driver.find_element_by_id('textarea')
text_area.send_keys("This text is send using Python code.")

每次我运行代码(包括executable_path = r'C:UsersuserDownloadschromedriver_win32' (时,当我使用可执行路径运行代码时,我都会收到一条权限错误消息。没有路径的代码减去用driver = webdriver.Chrome(options)替换的executable_path后是相同的,但我得到了错误消息argument of type 'Options' is not iterable

我们非常感谢对这个问题的任何帮助。诚然,我对Python和编码有点陌生,我正在尝试新的想法来更好地学习程序,但我试图找到答案的一切都会破坏我的代码。

尝试在executable_path参数的末尾添加可执行文件名:

executable_path = r'C:UsersuserDownloadschromedriver_win32chromedriver.exe'

我用于测试的代码:

from selenium import webdriver
import time
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(executable_path = r'C:UsersuserDownloadschromedriver_win32chromedriver.exe')
driver.get('http://codepad.org')
text_area = driver.find_element_by_id('textarea')
text_area.send_keys("This text is send using Python code.")

最新更新