0

I am trying to automate the log in process to WebAdvisor. I have tried to select the "Log In" button by calling different elements. Each attempt so far has been unsuccessful.

My current code:

path = '.../chromedriver

driver = webdriver.Chrome(path)

url = 'https://webadvisor.barry.edu/

driver.get(url)

The below have been unsuccessful.

driver.find_element_by_id('acctLogin').click()

driver.find_element_by_name('Log In').click()

driver.find_element_by_link_text("Log In").click()

This is the section of the code related to the button I am trying to click on in the WebAdvisor website:

Html code of WebAdvisor

The expected result is the log in page. At the moment it does not change page.

2 Answers 2

1

Your xpath is wrong, Please find below solution.

from selenium import webdriver
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path=r"chromedriver.exe")

driver.get("https://webadvisor.barry.edu/")


element=WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//li[@id='acctLogin']//span[@class='label'][contains(text(),'Log In')]")))
element.click()
element0=WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@id='USER_NAME']")))
element0.send_keys("Test123")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Rock! It works! Out of curiosity I tested it with 1 second and it still works. I tested it without the WebDriverWait method and it doesn't work. Why is the method WebDriverWait necessary?
1

Induce WebDriverWait And element_to_be_clickable() And following locator startegy.

Xpath:

driver=webdriver.Chrome(path)
driver.get("https://webadvisor.barry.edu/")
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//li[@id='acctLogin']/a[./span[contains(.,'Log In')]]"))).click()

CSS Selector:

driver=webdriver.Chrome()
driver.get("https://webadvisor.barry.edu/")
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#acctLogin >a"))).click()

You need to import following libraries.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

Browser Snapshot:

enter image description here

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.