Home > Software engineering >  How to click on link with text See more anyway using Selenium in Python?
How to click on link with text See more anyway using Selenium in Python?

Time:07-24

When using Selenium I tried to scroll down the page but I don't know how to click on the link with text See more anyway.

enter image description here

enter image description here

CodePudding user response:

To click on the element with text See more anyway you need to induce WebDriverWait for the element_to_be_clickable() which automatically scrolls the element within view and you can use the following locator strategy:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(., 'The rest of the results')]//span[contains(., 'See more anyway')]"))).click()
    
  • Or simply:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(., 'See more anyway')]"))).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
    
  • Related