简体   繁体   中英

Selenium python website login

I was trying over the past few hours , without success , to make webdriver.Firefox() run properly. I reinstalled geckodriver and verified it was added to the path , i tried to use FirefoxBinary but it didn't help. I could not find any solution , and I am not sure how to fix this , I would appreciate your help. This is the code :

#!/usr/bin/env python

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time
browser = webdriver.Firefox()
browser.get("https://testweb.com")                    
time.sleep(10)
username = browser.find_element_by_id("extpatid")
password = browser.find_element_by_id("extpatpw")
username.send_keys("username")
password.send_keys("password")
login_attempt = browser.find_element_by_xpath("//*[@type='submit']")
login_attempt.submit()

Below are the exceptions received when I tried to execute the script :

Traceback (most recent call last):
  File "./braude.py", line 7, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error

Python version :

# /usr/bin/python -V
Python 2.7.12+

I'm not sure why you have this line: from selenium.webdriver.firefox.firefox_binary import FirefoxBinary but it's completely unnecessary and likely related to your ultimate problem - a wrong version of the Firefox webdriver module.

Try Chrome and see how it reacts with that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM