Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!