如何通过Raspbian使geckodriver / chromedriver与selenium / python3一起使用

时间:2019-07-10 18:25:25

标签: python-3.x selenium selenium-webdriver raspbian

我一直在尝试使用Selenium 3.141.0和Python3.6在运行Raspbian的Pi上自动登录到某些网站。 Pi正在运行Chromium和Firefox-ESR 52.9(我无法安装最新版本的Firefox)。随着chromedriver不断出现执行错误,我继续尝试Firefox。

该脚本本质上只询问一次凭据,然后通过循环将其传递到每个URL中。我已经为Windows完善了它(是的,我已经将此版本的代码修改为对Linux友好)。我知道Pi使用ARM,可能无法与这些驱动程序一起使用(我尝试过许多版本的geckodriver)

Traceback (most recent call last):
  File "auto03.py", line 105, in <module>
    main_menu()
  File "auto03.py", line 46, in main_menu
    firefoxopen()
  File "auto03.py", line 79, in firefoxopen
    driver = webdriver.Firefox(geckodriver)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

根据我在进行故障排除时要进行的更改,错误基本上会在这三个之间切换:

selenium.common.exceptions.WebDriverException: Message: connection refused

selenium.common.exceptions.WebDriverException: Message: newsession

  File "auto01.py", line 4, in <module>
    driver=webdriver.Chrome('/usr/local/bin/chromedriver')
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error

我的代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from getpass import getpass
import time
import os
...
...
def firefoxopen():
    global driver
    driver = webdriver.Firefox('/usr/local/bin/geckodriver')
    driver.maximize_window()
...
def allboards():
    boards = [6 REDACTED VARIABLE NAMES POINT TO URLS]
    y = 1
    if y < 6:
        for x in boards:
            driver.get(x)
            driver.find_element_by_id('usernameBox').send_keys(VARIABLE FOR USERNAME)
            driver.find_element_by_id('passwordBox').send_keys(VARIABLE FOR PASSWORD)
            driver.find_element_by_id('loginButton').click()
            driver.find_element_by_link_text('Operations Center').click()
            # These lines open a new tab then switch to the tab specified by y (1st, 2nd, 3rd, etc).
            driver.execute_script("window.open('');")
            driver.switch_to.window(driver.window_handles[y])
            # This increments the variable one line up so that the next round of the loop moves to the next tab.
            y = y + 1

理想情况下,脚本会要求输入用户名/密码,打开Firefox,打开第一个URL,插入凭据,打开第二个URL,依此类推...

0 个答案:

没有答案