0
from selenium import webdriver 
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Chrome('/usr/local/Caskroom/chromedriver/chromedriver')
wait = WebDriverWait(driver, 20)
driver.implicitly_wait(10) 


driver.get('https://api.engage2learn.org/auth? response_type=token&client_id=esuite&state=cXd5VVlsQkViLWllVkpWLXZFelJfdDFoVTZHT1BkT19WQ3EySGVjQTVsSWNw&redirect_uri=https%3A%2F%2Fesuite.engage2learn.org%2Findex.html&scope=') 
email = driver.find_element(By. ID, 'loginform-username')
email.send_keys('email to log in')
password = driver.find_element(By.ID, 'loginform-password')
password.send_keys('password to log in')
driver.find_element(By.CSS_SELECTOR , 'button').click()
wait

Everything works up until the log in process starts and then the page resets to the orginal log in page with all fields cleared. The log in process works manually and their are no bots on the website. But as soon as the automation starts and the site starts to authenticate the log in credentials it resets to the orginal log in page with all fields cleared.

drafty
  • 17
  • 3

1 Answers1

0

It's difficult to give a proper solution without knowing the website and having login details, but an easy workaround would be to configure chromedriver to use a Chrome profile that is already logged into the site:

# Uses main chrome profile
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=/path/to/your/chrome/profile')

s = Service('chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)

driver.get(url);
Thorium
  • 191
  • 1
  • 14
  • So I got it to open my default profile but once it opens this error is raised:raise WebDriverException("Can not connect to the Service %s" % self.path) selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /Applications/Google Chrome.app/Contents/MacOS/Google Chrome – drafty Aug 23 '22 at 19:54
  • What version of Selenium are you using? Take a look at the response @undetected-selenium added to this post, it might solve your exception: https://stackoverflow.com/questions/64717302/deprecationwarning-executable-path-has-been-deprecated-selenium-python – Thorium Aug 23 '22 at 22:50
  • I'm a little confused on what my version of selenium has to do with it. I have the most recent version. I tried launching from my default browser and I am able to but the issue is that now selenium won't go to the website and raises the error I shared earlier. – drafty Aug 23 '22 at 23:10
  • Ah right, can you add this to your import statements and try again? `from selenium.webdriver.chrome.service import Service` – Thorium Aug 23 '22 at 23:42
  • Maybe you can help me understand how i got it to work. So I logged in manually from my default browser and then I copied the link to the site once logged in And saved the cookies and added them to the browser using selenium add.cookies. After adding the cookies my script attempts to log in. This worked and I thought it was because I added the cookies from the authentic log in but thats not the case. I have tried this on different computers already but for some reason I can log in with the script as long as I use the url for the site when logged in not the url to log in. Know why? – drafty Aug 24 '22 at 07:01
  • It sounds like that `/auth` route will always take you to a login page, and with the URL you've used in your example, you are also passing in a long query string that might be interfering – Thorium Aug 26 '22 at 00:46