Python Selenium: Clicking on the next page not working

I am using the following code to click on the next page, by clicking the next element.

However this code is not working. Any thoughts on what I might be doing wrong.

Final goal:

Use BeautifulSoup on each of the pages.

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from import By
from import WebDriverWait
from import expected_conditions as EC
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as ureq
import random
import time
from bs4 import BeautifulSoup
from import By

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)

# A randomizer for the delay
seconds = 1 + (random.random() * 2)
# create a new Chrome session
driver = webdriver.Chrome(chrome_options=chrome_options)
# driver.maximize_window()

# navigate to the application home page

next_page = driver.find_element(By.CLASS_NAME, "next")
#print (next_page.get_attribute('innerHTML'), type(next_page))
# next_page.find_element(By.LINK_TEXT("Next")).click()

This code does not click on the next page.

>Solution :

Select your element more specific and wait .until(EC.element_to_be_clickable()) – This will give you the next page.


from selenium import webdriver
from import By
from import WebDriverWait
from import expected_conditions as EC
from import Service
from import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

url = ''


WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#datatable_next a'))).click()

Leave a Reply