Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
Python selenium find element by xpath or css selector

how can i click on the "NATIONAL" text with python selenium

<div class="ellipsis__content">
    <ul class="breadcrumb_new" id="breadcrumb">
       <li>
         <span>NATIONAL</span>
       </li>
    </ul>
</div>

I tried these below things,

find_element_by_xpath("//div[@id='breadcrumb']/li/span")
find_element_by_css_selector("#breadcrumb > li > span")

Both the methods not working, any idea here

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Try this one, should work for you:

ele=driver.find_element_by_xpath("//*[@id='breadcrumb']//span")
ele.click()
about 4 years ago · Juan Pablo Isaza Relatório

0

Already this question has an answered but adding couple of points.

I tried these below things,

find_element_by_xpath("//div[@id='breadcrumb']/li/span")

The id breadcrumb is part of ul tag but you are referring div tag. It should work if try as below.

find_element_by_xpath("//ul[@id='breadcrumb']/li/span")

find_element_by_css_selector("#breadcrumb > li > span")

There is nothing wrong with CSS locator. It should work still if you are seeing issue you may need to debug and see or try by adding some explicit value.

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório

0

May be you need to wait till element is rendered properly.

Code trial 1 :

time.sleep(5)
driver.find_element_by_xpath("//div[@id='breadcrumb']/li/span").click()

Code trial 2 :

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='breadcrumb']/li/span"))).click()

PS : Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda