0

I am trying to automate the downloads of specific files for my organization. In doing so I came across Browser Automation with Selenium. I got to the point where I can inject user credentials, but now I need to login to the page by clicking on the login button.

Here is the parent URL, in which I inject my credentials https://www.accuplacer.org

Then I need to click on the login button. Here is the inspect output of that element:

<button type="submit" class="btn btn-lg btn-primary pull-left " ng-disabled="loginDisable &amp;&amp; isFullyLoaded">
                                    <!-- ngIf: loginSpin && !traceIE -->
                                    <!-- ngIf: loginSpin && traceIE -->
                                    Login
                                 </button>

Here is the code I have so far, I know it's basic, and I am working on cleaning it up and defining somethings into functions.

import selenium
import os
import unittest
import requests
import time
from selenium import webdriver

#URL Variables
login_url = 'https://www.accuplacer.org/'
redirect_url = 'https://www.accuplacer.org/api/home.html#/'
reports_scheduler_url = 'https://www.accuplacer.org/api/home.html#/reportScheduler'
custom_reports_url = 'https://www.accuplacer.org/api/home.html#/customReports'

#WebDriver Path
browser = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\chromedriver.exe")

browser.get("https://www.accuplacer.org")

username = browser.find_element_by_id("login")
password = browser.find_element_by_id("password")
#submit = browser.find_element_by_id("Login")
username.send_keys("uname")
password.send_keys("test")

#browser.send_keys(Keys.ENTER)
#browser.send_keys(Keys.RETURN)

#submit.click()
browser.find_element_by_css_selector('btn btn-log btn-primary pull-left').click()

2 Answers 2

2

Your CSS locator is wrong. Try with below css locator with explicit wait.

element = WebDriverWait(browser, 20).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, ".btn.btn-lg.btn-primary.pull-left")))
element.click();

For this piece of code you need below import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

5 Comments

Yeah, I just discovered that as well. I should have been using: browser.find_element_by_css_selector('.btn.btn-lg.btn-primary').click()
I was able to do it without the additional imports, but I may end up doing that to work in some functionality with the login button.
Explicit wait is standard practice to use so i have mentioned it too in answer
Any reason to leave out the <button> tag?
No specific reason. “TagName.ClassName” or “.className” both are correct CSS expression.
0

You can use the above, but I did not define the element in the way that Muzzamil did. Instead I just used the following for #submit.click

browser.find_element_by_css_selector('.btn.btn-lg.btn-primary').click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.