0

I'm trying to create an automated login system on Python using Selenium but I can't seem to be able to click on the "Login" button which uses a javascript code to send the login details.

Could someone let me know how I might be able to send the login details filled in by clicking on the "Login" button (more of a link it seems)?

The following is the div including the "Login" button.

<div class="btn-login">
<p>
<a href="javascript:cmdButton_push(document.MypageLoginActionForm);">Login</a>
</p>
</div>

XPATH:

//*[@id="login-form"]/div[1]/p/a

I've tried:

  1. click by finding the XPATH
  2. click by finding the text "Login" and neither have worked.

Please let me know should you have any questions. Thanks in advance!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

To click on the element with text as Login you can use either of the following Locator Strategies:

  • Using link_text:

    driver.find_element_by_link_text("Login").click()
    
  • Using css_selector:

    driver.find_element_by_css_selector("div.btn-login>p>a[href*='MypageLoginActionForm']").click()
    
  • Using xpath:

    driver.find_element_by_xpath("//div[@class='btn-login']/p/a[contains(@href, 'MypageLoginActionForm') and text()='Login']").click()
    

Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Login"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.btn-login>p>a[href*='MypageLoginActionForm']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='btn-login']/p/a[contains(@href, 'MypageLoginActionForm') and text()='Login']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352