3

I'm a complete beginner with selenium, sorry if the question is dumb (it is dumb):) I need to find Speed test link on https://www.netflix.com/ and then click it.

i've tried searching by text and some other options. But nothing seems to work, I don't know why.

from selenium import webdriver
from selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("https://www.netflix.com/")
driver.implicitly_wait(10)
elem = driver.find_element_by_link_text("Speed test")
elem.click()

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Sign in"} (Session info: chrome=75.0.3770.142)

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

2 Answers2

2

The element with text as Speed Test is out ofthe Viewport so you need to induce WebDriverWait for the desired element to be clickable() and you can use the following Locator Strategy:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='footer-link']/span[text()='Speed Test']"))).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
1

Use WebDriverWait and element_to_be_clickable with following xpath.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.netflix.com/")
elem = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//span[@data-uia='data-uia-footer-label'][contains(.,'Speed Test')]")))
elem.click()

Browser snapshot:

enter image description here

To added to this answer you need to use WebDriverWait and then click on the element Show more info

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.netflix.com/")
elem = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//span[@data-uia='data-uia-footer-label'][contains(.,'Speed Test')]")))
elem.click()
WebDriverWait(driver,60).until(EC.element_to_be_clickable((By.XPATH,"//a[contains(.,'Show more info' )]"))).click()
JeffC
  • 22,180
  • 5
  • 32
  • 55
KunduK
  • 32,888
  • 5
  • 17
  • 41