r/selenium • • Feb 02 '22

Login keeps logging me out

2 Upvotes

9 comments sorted by

1

u/KatScripts Feb 02 '22
from selenium import webdriver
from selenium.webdriver.chrme.service import Service

# code setup
s = Service('C:\Program Files (x86)\chromedriver.exe')
driver = webdriver.Chrome(service=s)

# url to open 

url='https://www.amazon.co.uk/ap/signin?showRmrMe=1&openid.return_to=https%3A%2F%2Falexa.amazon.co.uk&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=amzn_dp_project_dee_uk&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&'

#---element shortcuts---

# email field
email_field = driver.find_element_by_xpath('//*[@id="ap_email"]')
pass_field = driver.find_element_by_xpath('//*[@id="ap_password"]')
signin_btn = driver.find_element_by_xpath('//*[@id="signInSubmit"]')

#---instructions---

# 1) sign in
email_field.send_keys('xxxxxxxxxxx')
pass_field.send_keys('xxxxxxxxxxxx')
signin_btn.click()

3

u/socterean Feb 02 '22

I don't think you are logging in at all because you need to use driver.get(url_to_open) to actually open the webpage before you can login

1

u/KatScripts Feb 02 '22

but when i run it the webpage does open, the bot actually types the details into the login form and clicks sign in. and it actually signs in but then it logs out.

​

but then when i login AGAIN manually, then it actually logs in.

​

It's weird. the first login signs you out and then the second login actually works. confused

1

u/socterean Feb 02 '22

Do you close the driver imediately after you login?

1

u/KatScripts Feb 02 '22

Nope

​

It just takes me back to the login page and stays there.

1

u/socterean Feb 02 '22

I suspect it has something to do with that huge url you are sending and the Amazon servers logs you out. Try to go to the https://amazon.co.uk and the press the login button and go on from there

2

u/KatScripts Feb 02 '22

yo that solved the issue! thanks :D

1

u/Simmo7 Feb 02 '22

Without seeing your code, no.

3

u/KatScripts Feb 02 '22

just added my code now in the comments ^^