0

I'm fairly new to developing but I'm having a problem logging into a website. The code I have currently typed in the username, password, and correctly clicks the log in button. However, the page simply refreshes but doesn't actually log in. The web page is using some sort of AWS authentication maybe that's why I'm not getting through, does anyone have any experience getting past this?

Here's the code I have right now:

from selenium import webdriver

username = "Username"
password = "Password"
driver = webdriver.Chrome("locationpath\\chromedriver.exe")
driver.get("website")
username_textbox = driver.find_element_by_id("signInFormUsername")
username_textbox.send_keys(username)
password_textbox = driver.find_element_by_id("signInFormPassword")
password_textbox.send_keys(password)
login_button = driver.find_element_by_name("signInSubmitButton")
login_button.submit()

2 Answers 2

1

https://selenium-python.readthedocs.io/api.html gives difference between submit() and click().

The submit() function is an easier way to submit a form :

from selenium import webdriver

username = "Username"
password = "Password"
driver = webdriver.Chrome("locationpath\\chromedriver.exe")
driver.get("website")
username_textbox = driver.find_element_by_id("signInFormUsername")
username_textbox.send_keys(username)
password_textbox = driver.find_element_by_id("signInFormPassword")
password_textbox.send_keys(password)
password_textbox.submit()

Here we need to identify only the username and password field, you don't have to find the submit button .

If you are using click():

from selenium import webdriver

username = "Username"
password = "Password"
driver = webdriver.Chrome("locationpath\\chromedriver.exe")
driver.get("website")
username_textbox = driver.find_element_by_id("signInFormUsername")
username_textbox.send_keys(username)
password_textbox = driver.find_element_by_id("signInFormPassword")
password_textbox.send_keys(password)
login_button = driver.find_element_by_name("signInSubmitButton")
login_button.click()

you have to find the submit button and click it.

Difference:

So the only difference is that click() will simulate the user action, and submit() will trigger the submit action.

If you are testing a form page, then it's better to use click and ensure that submit button works. (On submit button click submit event is triggered internally)

0

The submit() method should be used on a form element, not a button. On buttons use click() to interact with them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.