0

I'm using Selenium with Python to navigate through a webpage and want to click on such Element:

<td style="width:75px;cursor:pointer;" onclick="$(this).up().addClassName('grid-visited'); showIndicator(); document.location.href='/masterdata/show/id/1'">591000397</td>

I tried a some stuff which didn't work, e.g.

browser.find_element_by_css_selector("td[onclick*=pointer]").click()

or

browser.find_element_by_link_text("591000397").click()

Error message be like

Message: no such element: Unable to locate element: {"method":"css selector","selector":"td[onclick*=pointer]"}

Thank you for your help

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
davvpo
  • 39
  • 3

1 Answers1

0

To click on the element with text as 591000397 you can use either of the following Locator Strategies:

  • Using xpath:

    browser.find_element_by_xpath("//td[contains(@onclick, 'grid-visited') and contains(@onclick, 'masterdata')][text()='591000397']").click()
    

Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using XPATH:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[contains(@onclick, 'grid-visited') and contains(@onclick, 'masterdata')][text()='591000397']"))).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
    

References

You can find a couple of relevant discussions on NoSuchElementException in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352