Click on Load more element using Selenium and Python

Solution 1:

To click on the element with text as Load more you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using XPATH and text()[contains()]:

    driver.get("https://www.legit.ng/tag/road-accidents-in-nigeria/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[text()[contains(.,'Load more')]]"))).click()
    
  • Using XPATH and contains():

    driver.get("https://www.legit.ng/tag/road-accidents-in-nigeria/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(., 'Load more')][./p[text()]]"))).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