Question

I am trying to login into a website using Selenium. The website is http://projecteuler.net/login.

from selenium import webdriver

browser = webdriver.Chrome()

browser.get('http://projecteuler.net/login')
username = browser.find_element_by_id('username')
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 upto 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 giving problem. 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?

There is a weird thing happening. When I have done 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

Was it helpful?

Solution

Try click() instead of submit()

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

Source:- http://selenium.googlecode.com/git/docs/api/py/selenium/selenium.selenium.html?highlight=submit#selenium.selenium.selenium.submit

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top