0

I need to click on:

<h3 class="submenu" style="background-position: 0px -68px;">Envio de Ordens de Operações com Ativos Financeiros</h3>

This is my code:

driver.find_element(By.XPATH, '//*[@id="conteudo"]/div[2]/div[3]/div[1]/div[1]/h3').click()

I already tried by xpath and class_name but its not working.

This is the error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Matheus
  • 11
  • 5

1 Answers1

0

As per the given HTML:

<h3 class="submenu" style="background-position: 0px -68px;">Envio de Ordens de Operações com Ativos Financeiros</h3>

To click on the element with text as Envio de Ordens de Operações com Ativos Financeiros you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h3[@class='submenu' and starts-with(., 'Envio de Ordens de Opera')]"))).click()
    
  • Using XPATH and full innerText:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h3[text()='Envio de Ordens de Operações com Ativos Financeiros']"))).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