jww*_*jww 6 selenium arm chromium python-3.x selenium-chromedriver
我过去几个月一直在使用的 Python 脚本今天坏了。该脚本监视调制解调器的来电和文件 FTC Do Not Call 投诉。错误是InvalidArgumentException: Message: invalid argument: value must be a non-negative integer在调用implicitly_wait.
我发现了类似的 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)
这是来自 的 Selenium 函数/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py:
# 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
...
| 归档时间: | 
 | 
| 查看次数: | 3045 次 | 
| 最近记录: |