2

This script with Selenium in Python 3 helps me to scrape data from a page by clicking the see all button, but it stopped working and I do not know the cause. Could you help me with the code?

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

nav= Service(ChromeDriverManager().install())
driver= webdriver.Chrome(service= nav)

driver.get('https://getdaytrends.com/es/venezuela/#moreTrends')
                   
driver.find_element(By.CLASS_NAME,'btn btn-outline-primary px-5')
driver.execute_script("arguments[0].click();", search)

datos= driver.find('table')

The Traceback is:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn btn-outline-primary px-5"}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
aKratos
  • 191
  • 10

1 Answers1

1

To click on Ver todo 34 you need to scrollIntoView() the desired element and induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

driver.get("https://getdaytrends.com/es/venezuela/#moreTrends")
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='icon icon-longest-lasting']")))
driver.execute_script("arguments[0].scrollIntoView(true);", element)
WebDriverWait(driver, 7).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-outline-primary px-5']"))).click()

Browser Snapshot:

getdaytrends

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