0

I'm trying to click on a part of a webpage, but I'm getting the message "NoSuchElementException: Unable to locate element"....despite the element is there.

The code used to work, however it looks like there was a change in the page..but the xpath did not changed.

I tried different solutions of similar questions here in Stackoverflow, but something is not correct yet for this example.

The URL is: "http://www.bmfbovespa.com.br/pt_br/servicos/market-data/consultas/mercado-a-vista/codigo-isin/pesquisa/"

The element I`m trying to click : "Download de Arquivos"

My code:

from selenium import webdriver 


fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/vnd.ms-excel, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
fp.set_preference('browser.helperApps.alwaysAsk.force', False) 



driver = webdriver.Firefox(firefox_profile=fp)
driver.get("http://www.bmfbovespa.com.br/pt_br/servicos/market-data/consultas/mercado-a-vista/codigo-isin/pesquisa/")

###
# Click "Download de arquivos" (the part with problem)
###

elem=driver.find_element_by_xpath(".//*[@id='ctl00_contentPlaceHolderConteudo_rtsDetalhe_tabDownload']/span/span")
elem.click()

Any thoughts?

1 Answer 1

1

Multiple options here:

  • locate the link "by id":

    driver.find_element_by_id("ctl00_contentPlaceHolderConteudo_rtsDetalhe_tabDownload")
    
  • by link text via the "by xpath" locator:

    driver.find_element_by_xpath("//a[span/span = 'Download de Arquivos']")
    

And, the important part is that the element is inside an iframe - you need to switch to it.

Working code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("http://www.bmfbovespa.com.br/pt_br/servicos/market-data/consultas/mercado-a-vista/codigo-isin/pesquisa/")

driver.switch_to.frame("bvmf_iframe")

wait = WebDriverWait(driver, 10)
elem = wait.until(EC.presence_of_element_located((By.ID, "ctl00_contentPlaceHolderConteudo_rtsDetalhe_tabDownload")))
elem.click()
Sign up to request clarification or add additional context in comments.

1 Comment

I tried both....but I'm still getting the "NoSuchElementException: Unable to locate element:" message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.