0

I am trying to click on the "Training material statistics" by using the following code in Python, but it didn't work:

WebDriverWait(driver,20)\
    .until(EC.element_to_be_clickable((By.XPATH,'//*[@id="report-navigation"]/div[2]')))\
    .click()

HTML:

<div id="report-navigation">
    <div class="report-nav-btn active" onclick="Report.changeGrid(this, 'report-users-grid')">
       User statistics          
       <div class="report-nav-arrow active"></div>
    </div>
    <div class="report-nav-btn" onclick="Report.changeGrid(this, 'report-objects-grid')">
       Training material statistics         
       <div class="report-nav-arrow"></div>
    </div>
    <div class="report-nav-btn" onclick="Report.changeGrid(this, 'report-deliverables-grid')">
       Learner assignments          
       <div class="report-nav-arrow"></div>
    </div>
</div>

HTML Snapshot:

HTML Image

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

1 Answers1

0

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 CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#report-navigation div[onclick*='report-objects-grid']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='report-navigation']//div[contains(@onclick, 'report-objects-grid')]"))).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