0

I am writing a script to automate data collection and was having trouble clicking a link. The website is behind a login, but I navigated that successfully. I ran into problems when trying to navigate to the download page. This is in python using chrome webdriver.

I have tried using:

find_element_by_partial_link_text('stuff').click()
find_element_by_xpath('stuff').click()
#and a few others

I get iterations of following message when I try a few of the selector statements.

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"partial link text","selector":"download"}
  (Session info: chrome=88.0.4324.182)

Html source I'm trying to use is:

<a routerlink="/download" title="Download" href="/itron-mvweb/download"><i class="fa fa-lg fa-fw fa-download"></i><span class="menu-item-parent">Download</span></a>

Thank you!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Zachary Wyman
  • 299
  • 2
  • 11

2 Answers2

2

This is caused by a typo. Download is case-sensitive, make sure you capitalize the D!

Seth
  • 2,214
  • 1
  • 7
  • 21
0

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

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "a[title='Download'][href='/itron-mvweb/download'] span.menu-item-parent").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//a[@title='Download' and @href='/itron-mvweb/download']//span[@class='menu-item-parent' and text()='Download']").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 CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[title='Download'][href='/itron-mvweb/download'] span.menu-item-parent"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@title='Download' and @href='/itron-mvweb/download']//span[@class='menu-item-parent' and text()='Download']"))).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