user11750176
user11750176

Reputation:

Can't use firefox driver to open a website

I'm trying to login a website with python and selenium. I think there is something wrong with the geckodriver. I have installed the latest version of both firefox and gecko driver but it still doesn't work. I have tried the following. It worked before I reinstalled my Windows and it used to work :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("https://www.instagram.com/accounts/login/")

username =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']")))
password =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='password']")))
username.clear()
username.send_keys("My Username")
password.clear()
password.send_keys("My Password")
try:
    element = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//button[@type='submit']"))
    )
finally:
    element.click()

if len(driver.find_elements_by_xpath("//form[@id='slfErrorAlert']"))>0:
    # Element is present
    print("Not!")
else:
    # Element is not present
    print ("Logged IN!")

Here's the error:

>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>> from selenium.webdriver.common.by import By
>>> from selenium.webdriver.support.ui import WebDriverWait
>>> from selenium.webdriver.support import expected_conditions as EC
>>>
>>> driver = webdriver.Firefox()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

>>> driver.get("https://www.instagram.com/accounts/login/")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
>>>
>>> username =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
>>> password =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='password']")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
>>> username.clear()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'username' is not defined
>>> username.send_keys("My Username")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'username' is not defined
>>> password.clear()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'password' is not defined
>>> password.send_keys("My Password")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'password' is not defined
>>> try:
...     element = WebDriverWait(driver, 10).until(
...         EC.element_to_be_clickable((By.XPATH, "//button[@type='submit']"))
...     )
... finally:
...     element.click()
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
NameError: name 'driver' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
NameError: name 'element' is not defined
>>> if len(driver.find_elements_by_xpath("//form[@id='slfErrorAlert']"))>0:
...     # Element is present
...     print("Not!")
... else:
...     # Element is not present
...     print ("Logged IN!")
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined

Any response would be appreciated

Upvotes: 3

Views: 200

Answers (1)

user11750176
user11750176

Reputation:

You must still have the Microsoft Visual Studio redistributable runtime installed on your system for the binary to run.

Upvotes: 1

Related Questions