Selenium, Python и InvalidArgumentException: неверный аргумент: значение должно быть неотрицательным целым числом - PullRequest
2 голосов
/ 19 июня 2019

Скрипт Python, который я использовал последние несколько месяцев, сегодня сломался.Скрипт контролирует модем на наличие входящих звонков и файлов FTC Do Not Call на жалобы.Ошибка: InvalidArgumentException: Message: invalid argument: value must be a non-negative integer при вызове implicitly_wait.

Я нашел похожие отчеты для Firefox , но я не нашел ни одного дляХром.Машина полностью исправлена, поэтому обновлять нечего, как в отчетах 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 Dev-Board Тритий 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
...
...