Reputation: 47
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:
The expected result is the log in page. At the moment it does not change page.
Upvotes: 0
Views: 51
Reputation: 4177
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")
Upvotes: 1
Reputation: 33384
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:
Upvotes: 1