Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I am trying to log into a website using Selenium. 

username = browser.find_element_by_id('username')

from selenium import webdriver

browser = webdriver.Chrome()

browser.get('http://www.google.com')

username.send_keys(USERNAME_HERE)

password = browser.find_element_by_name('password')

password.send_keys(PASSWORD_HERE)

browser.find_element_by_name("login").submit()

The program is working correctly up to on the last statement. I tried omitting the last statement and manually logged in and it worked. But when I added the last statement and ran the program it just seemed to reload the same page minus the information that I had placed via the program.

So it is only the submission that is being given. I viewed the source and confirmed whether there is some other element by that name but there was no other element by name "login". So what am I getting wrong here? Do I need to take care of something else also?

Something weird is happening. Once I have done the form submission via code and try to view the source in Google Chrome 33.0.1750.154 m I am getting the below. enter image description here

1 Answer

0 votes
by (62.9k points)

Try using click() instead of submit()

Submit is particularly useful for forms without submit buttons, e.g. single-input “Search” forms.

In your case, there is a submit button, better to just click it.

Browse Categories

...