V
V
Valery Orlov2019-10-29 02:20:00
Python
Valery Orlov, 2019-10-29 02:20:00

How does Selenium authorize on websites?

Good day.
My Python + Selenium authorization example:

from selenium import webdriver  
chromedriver = 'D:\\temp\\selenium\\chromedriver.exe'   
browser = webdriver.Chrome(executable_path=chromedriver)
browser.get('https://example.com/login/')
email = browser.find_element_by_id('email')
password = browser.find_element_by_id('password')
login = browser.find_element_by_id('submit')
email.send_keys('my_mail')
password.send_keys('my_pass')
login.click()

When I try to enter my personal account, I receive an SMS with a code to confirm authorization. If I go through the usual chrome, then I get without any verification SMS. Hence, the work of all automation is disrupted.
The following thoughts come to mind:
1. Maybe it's cookies? How is a real chrome request different from a selenium request?
2. How to check the work through the connection of the original Chrome application? I saw somewhere that this is possible.
3. Is it possible to use cookies from chrome to skip authorization?
Thanks for any advice!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2019-10-29
@coderisimo

It's a creative process! ))) To begin with, what is your user agent? HeadlessChrome? If so, use something more appropriate.

from selenium.webdriver.chrome.options import Options
opts = Options()
opts.add_argument("user-agent=здесь какой-нибудь Хром Юзер Агент", executable_path=chromedriver)

browser = webdriver.Chrome(chrome_options=opts)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question