Selenium,Python和InvalidArgumentException:无效参数:value必须为非负整数

时间:2019-06-19 17:19:30

标签: python-3.x selenium arm selenium-chromedriver chromium

我过去几个月一直使用的Python脚本今天坏了。该脚本监视调制解调器的传入呼叫,并向FTC请勿呼叫投诉发送文件。呼叫 InvalidArgumentException: Message: invalid argument: value must be a non-negative integer 时错误为 implicitly_wait

我找到了类似的reports for Firefox,但我没有找到适用于Chrome的浏览器。该机器已完全打补丁,因此没有像Firefox报告中那样需要更新。

问题出在哪里,我该如何解决?


这是脚本:

$ cat test.py
#!/usr/bin/env python3

import sys
import selenium
import os.path

from packaging import version
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def get_chrome():
    if os.path.isfile('/usr/bin/chromium-browser'):
        return '/usr/bin/chromium-browser'
    elif os.path.isfile('/usr/bin/chromium'):
        return '/usr/bin/chromium'
    elif os.path.isfile('/usr/bin/chrome'):
        return '/usr/bin/chrome'
    elif os.path.isfile('/usr/bin/google-chrome'):
        return '/usr/bin/google-chrome'
    else:
        return None

def main():
    opts = Options()
    opts.binary_location = get_chrome()
    opts.add_argument('--headless')
    opts.add_argument('--no-sandbox')
    opts.add_argument('--disable-dev-shm-usage')

    driver = webdriver.Chrome(chrome_options=opts)
    driver.maximize_window()

    agent = driver.execute_script('return navigator.userAgent')
    driver.get("https://complaints.donotcall.gov/complaint/complaintcheck.aspx")
    driver.implicitly_wait(2)
    driver.quit()

if __name__ == "__main__":
    main()

这里是例外:

$ python3 test.py
Traceback (most recent call last):
  File "test.py", line 39, in <module>
    main()
  File "test.py", line 35, in main
    driver.implicitly_wait(2)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 793, in implicitly_wait
    'implicit': int(float(time_to_wait) * 1000)})
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: value must be a non-negative integer
  (Session info: headless chrome=75.0.3770.90)

这是/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py中的Selenium函数:

# Timeouts
def implicitly_wait(self, time_to_wait):
    """
    Sets a sticky timeout to implicitly wait for an element to be found,
       or a command to complete. This method only needs to be called one
       time per session. To set the timeout for calls to
       execute_async_script, see set_script_timeout.

    :Args:
     - time_to_wait: Amount of time to wait (in seconds)

    :Usage:
        driver.implicitly_wait(30)
    """
    if self.w3c:
        self.execute(Command.SET_TIMEOUTS, {
            'implicit': int(float(time_to_wait) * 1000)})
    else:
        self.execute(Command.IMPLICIT_WAIT, {
            'ms': float(time_to_wait) * 1000})

这里是规格。该机器是ARM​​开发板Tritium H3

$ lsb_release -a
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic
...

$ python3 --version
Python 3.6.8

$ chromium-browser --version
Chromium 75.0.3770.90 Built on Ubuntu

$ apt-cache show python3-selenium
Package: python3-selenium
Architecture: all
Version: 3.8.0+dfsg1-3
...

$ apt-cache show chromium-chromedriver
Package: chromium-chromedriver
Architecture: armhf
Version: 75.0.3770.90-0ubuntu0.18.04.1
...

0 个答案:

没有答案