1

Selenium does not find the button "Consultar". I already tried copying and finding by xpath, id, partial_text, and text.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select

url = 'https://www.anbima.com.br/pt_br/informar/sistema-reune.htm'
driver = webdriver.Chrome(executable_path= r"/Users/Test/chromedriver")
driver.get(url)

Information about the button :

<img src="../img/bt_consultar.gif" name="Consultar" onclick="VerificaSubmit()" style="cursor: pointer; cursor:pointer;">
Vopix01
  • 13
  • 3

1 Answers1

0

The Consultar button element is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

    • Using css_selector:

      driver.get('https://www.anbima.com.br/pt_br/informar/sistema-reune.htm')
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#LGPD_ANBIMA_global_sites__text__btn"))).click()
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src='https://www.anbima.com.br/informacoes/reune/default.asp']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img[name='Consultar'][src*='bt_consultar']"))).click()
      
    • Using xpath:

      driver.get('https://www.anbima.com.br/pt_br/informar/sistema-reune.htm')
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='LGPD_ANBIMA_global_sites__text__btn']"))).click()
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@src='https://www.anbima.com.br/informacoes/reune/default.asp']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[@name='Consultar' and contains(@src, 'bt_consultar')]"))).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
  • Thanks for replying, but the methods above continue to present the same error of `no such element: Unable to locate element` – Vopix01 Feb 28 '22 at 21:19
  • Checkout the updated answer and let me know the status. – undetected Selenium Feb 28 '22 at 21:25
  • I just ran using xpath and css_selector and i got some errors with this line of code : `WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#LGPD_ANBIMA_global_sites__text__btn"))).click()` After I erased it, the webdriver found the button. – Vopix01 Mar 01 '22 at 16:40