1

I am trying to automate logging into my salesforce account. When I use my code:

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

browser= webdriver.Firefox()
browser.get("https://xxxxx.my.salesforce.com/? 
SAMLRequest=&startURL=%2Fidp%2Flogin%3Fapp% 
3D0sp0g000000Gmhj&un=xxxxx.xxxxx%40xxxxx.com")

elem=browser.find_element_by_id("username")
elem.send_keys("xxxxx.xxxx@xxxxx.com")
elem_pass=browser.find_element_by_id("password")
elem_pass.send_keys("xxxxxxx")
rem_me=browser.find_element_by_id("rememberUn")
rem_me.click()
elem.send_keys(Keys.ENTER)

As you can see, I pass the link to the url, pass the usname, password and remember me.

When I run this with Selenium, it goes to a email 2FA authentication page.

But when I do it manually:

Copy the url mentioned above.

Paste it into the address bar of firefox browser.

The uname and pass show already populated.

When I hit enter, it logs me in. (No 2FA).

Is Salesforce somehow detecting that request is from selenium?

And is there a way to get around it? Could this be related to this?

Different results when using Selenium + Python

  • Are you doing the same manually in incognito mode? Because selenium runs by default in incognito mode. Probably it is the reason for difference – Andrei Suvorkov Jul 10 '18 at 20:26
  • 1
    Yup, I got it resolved. I had to import cookies from Firefox, and use them with Selenium. from selenium import webdriver from selenium.webdriver.common.keys import Keys import os os.chdir("C:\\Users\\tsingh\\Desktop\\Cookies") ffprofile = webdriver.FirefoxProfile('C:\\Users\\tsingh\\Desktop\\Cookies') browser = webdriver.Firefox(firefox_profile=ffprofile) – Sunny Singh Jul 10 '18 at 21:09
  • @SunnySingh Add the resolution you mentioned as a comment as the answer for the benefit of the future readers. – undetected Selenium Jul 11 '18 at 08:16

1 Answers1

0

Yup, I got it resolved. I had to import cookies from Firefox, and use them with Selenium. from selenium import webdriver from selenium.webdriver.common.keys import Keys import os os.chdir("C:\Users\tsingh\Desktop\Cookies") ffprofile = webdriver.FirefoxProfile('C:\Users\tsingh\Desktop\Cookies') browser = webdriver.Firefox(firefox_profile=ffprofile)