Python Forum
Python-selenium script for automated web-login does not work - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Python-selenium script for automated web-login does not work (/thread-20972.html)



Python-selenium script for automated web-login does not work - hectorKJ - Sep-09-2019

Objective is to login into a website, pass some search parameters and open top 3 results.
However, I am stuck at the first step. Using Python 3.7 on Spyder (Anaconda). Individual commands work fine on console.

However, after the last command, browser throws following error: "Sorry, we could not authenticate you. Try again."

The Log In page however is a redirection from the URL below, to "https://accounts.sap.com/saml2/idp/sso/accounts.sap.com".
However, since the elements are located correctly and values passed, I suppose that isn't an issue. Clueless, why does the browser not accept login. Any support would be greatly appreciated.

Browser response is consistent in both Chrome and Firefox.

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

url="https://launchpad.support.sap.com"

browser = webdriver.Firefox()
browser.get(url)

time.sleep(10)
loginElem=browser.find_element_by_id("j_username")
pwdElem=browser.find_element_by_id("j_password")
submitElem=browser.find_element_by_id("logOnFormSubmit")

loginElem.clear()
loginElem.send_keys=('UserIDXXXXXX')
pwdElem.clear()
pwdElem.send_keys=('PasswordXXXXX')
submitElem.click()



RE: Python-selenium script for automated web-login does not work - hectorKJ - Sep-10-2019

I figured that the problem lies with "send_keys". It is not populating the fields, leaving it empty and hence the error.

Now, I am using latest Selenium and Python versions, not sure what else could be causing the issue. Any suggestions?


RE: Python-selenium script for automated web-login does not work - buran - Sep-10-2019

it should be loginElem.send_keys('UserIDXXXXXX')
what you do is to assign a string to loginElem.send_keys property thus overriding the method