0

Can't click on the download link using Selinium Webdriver

I'm trying to automate my weekly anime routes using python

from selenium import Webdriver
import time


dr = webdriver.Chrome()
time.sleep(3)
dr.get('https://horriblesubs.info/shows/one-punch-man-s2')
time.sleep(1)
link=dr.find_element_by_class_name("rls-info-container").click()
time.sleep(3)
blink=dr.find_element_by_xpath("//span[@class='dl_type hs-magnet-link']").click()
time.sleep(6)
dr.quit()

This is the error i get

Traceback (most recent call last):
  File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\Scripts\get-ShieldHero.py", line 16, in <module>
    blink=dr.find_element_by_xpath("//span[@class='dl_type hs-magnet-link']").click()
  File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
  File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[@class='dl_type hs-magnet-link']"}
  (Session info: chrome=74.0.3729.169)
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)

I want to click on the 480 link, but I can't with the above code

I've attempted other variations where I try and inspect the html block, but I've been unsuccessful.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
hamdoe
  • 111
  • 1
  • 1
  • 6

1 Answers1

0

To click() on the link with text as Magnet for the item One Punch Man S2 you need to click the <a> node within the <span> node and you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(., 'One Punch Man S2')]//following::span[@class='dl-type hs-magnet-link']/a"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352