Nggarap
Nggarap

Reputation: 63

Cannot click tag <a> with <i class> selenium python

I want to make a simple attendance automation with python for my college, I make this for ease, because this took so many button to click but, I cannot click the tag <a> with tag <i> inside it.

<a href="http://siakad.polinema.ac.id/mahasiswa/tr_absensi/add" 
class="btn btn-sm green-meadow btn-add-data" id="btn-add-wizard">
<i class="fa fa-plus"></i> Absen</a>

I use this wait function, and still not directed into that link. It shows nothing on result. Process finished with exit code 0

wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//a[contains(@href, ""'http://siakad.polinema.ac.id/mahasiswa/tr_absensi/add')]"))).click()

I tried using ID and LINK_TEXT and still showing Process finished with exit code 0.

Thank you, apologize for my english. Enghlish is not my main language. If you need more information about my question, please let me know.

Upvotes: 0

Views: 360

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193088

To click on the element with text as Absen you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-sm.green-meadow.btn-add-data#btn-add-wizard[href$='id/mahasiswa/tr_absensi/add']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-sm green-meadow btn-add-data' and @id='btn-add-wizard'][contains(@href, 'id/mahasiswa/tr_absensi/add')]"))).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
    

Upvotes: 1

Related Questions