【问题标题】:Why is my webdriver.chrome() not working?为什么我的 webdriver.chrome() 不起作用?
【发布时间】:2020-04-12 02:31:49
【问题描述】:

在我对这个问题的 cmets 进行抨击之前,我很清楚这可能与 this link 重复,但提供的答案并没有帮助我解决我的代码实例,即使在应用了调整后的版本我的代码中的答案。我查看了很多答案,包括将 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:\Users\user\Downloads\chromedriver_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:\Users\user\Downloads\chromedriver_win32' ,当我使用可执行路径运行代码时,我都会不断收到权限错误消息。 我没有路径的代码与我用driver = webdriver.Chrome(options) 替换的executable_path 相同,但我收到错误消息argument of type 'Options' is not iterable。

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

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver chrome-options


    【解决方案1】:

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

    executable_path = r'C:\Users\user\Downloads\chromedriver_win32\chromedriver.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:\Users\user\Downloads\chromedriver_win32\chromedriver.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.")
    

    【讨论】:

    • 当我在将 execuable_path 参数添加到 options 变量后运行代码时,我得到了一个 TypeError: __init__() got an unexpected keyword argument 'executable_path'。并且 Executable Path 参数已添加到驱动程序变量中,如我上面的代码所示。
    • @MichaelPate 我将用于测试的代码添加到我的答案中。它在我这边工作得很好。您对其进行了任何更改吗?
    • 我收到一条权限错误消息。它可能只是我的设备,这真的很烦人,但我有一个只需要适当权限的工作代码。因此,如果代码对您有效,那只是我的设备有问题。
    猜你喜欢
    • 1970-01-01
    • 2015-09-25
    • 2018-03-05
    • 2013-04-19
    • 2015-10-17
    • 2016-02-20
    • 2023-04-03
    • 2012-01-07
    • 2012-06-11
    相关资源
    最近更新 更多