Skip to content
Advertisement

using selenium.click() to change pages but gets error

I’m trying to click on a div to get to the next page of a table (the url does not change when the page changes). The go to the next page div has the same class as the go to the previous page’s. ive used:

elem = driver.find_element_by_class_name('cXQSjq')
elem.click()

timeout = 30
try:
    WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, "gxzFwa")))
except TimeoutException:
    driver.quit()
        
names = driver.find_elements_by_class_name('iBSZGH')
for company in names[1:]:
    name.append(company.text)
        
mostdata = driver.find_elements_by_class_name('gvgMSe.gJYnHB')
for most in mostdata:
    most = most.text
    most = most.replace(',','')
    data.append(most)

last7dsales = driver.find_elements_by_class_name('fGpHsy.kpsxyE')
for last in last7dsales:
    last = last.text
    last = last.replace(',','')
    last7day.append(last)

#loop for the  other pages:
for i in range(6):

    elem.click()
    
    timeout = 30
    try:
        WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, "gxzFwa")))
    except TimeoutException:
        driver.quit()
        
    names = driver.find_elements_by_class_name('iBSZGH')
    for company in names[1:]:
        name.append(company.text)
        
    mostdata = driver.find_elements_by_class_name('gvgMSe.gJYnHB')
    for most in mostdata:
        most = most.text.replace(',','')
        most = most.text.replace(',','')
        data.append(most)

    last7dsales = driver.find_elements_by_class_name('fGpHsy.kpsxyE')
    for last in last7dsales:
        last = last.text.replace(',','')
        last7day.append(last)

and it worked to get me to page 2, but after page 2 it gives me the error:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click 
intercepted: Element <div class="styles__Chevron-sc-1buchb9-1 cXQSjq">...</div> is 
not clickable at point (702, 656). Other element would receive the click: <div 
id="hs-eu-cookie-confirmation-inner">...</div>
(Session info: chrome=92.0.4515.107)

Do you know if there is an issue that i am able to call elem.click() after using selenium to find other parts of the page. I’m scraping data from https://nonfungible.com/market/history

Advertisement

Answer

I guess the issue here is that the next page button appears on the bottom of the page, so to click on it you should first scroll this element into the view.
See if this will work now:

from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)

elem = driver.find_element_by_class_name('cXQSjq')
actions.move_to_element(elem).perform()
time.sleep(0.3)
elem.click()

timeout = 30
try:
    WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, "gxzFwa")))
except TimeoutException:
    driver.quit()
        
names = driver.find_elements_by_class_name('iBSZGH')
for company in names[1:]:
    name.append(company.text)
        
mostdata = driver.find_elements_by_class_name('gvgMSe.gJYnHB')
for most in mostdata:
    most = most.text
    most = most.replace(',','')
    data.append(most)

last7dsales = driver.find_elements_by_class_name('fGpHsy.kpsxyE')
for last in last7dsales:
    last = last.text
    last = last.replace(',','')
    last7day.append(last)

#loop for the  other pages:
for i in range(6):
    actions.move_to_element(elem).perform()
    time.sleep(0.3)
    elem.click()
    
    timeout = 30
    try:
        WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, "gxzFwa")))
    except TimeoutException:
        driver.quit()
        
    names = driver.find_elements_by_class_name('iBSZGH')
    for company in names[1:]:
        name.append(company.text)
        
    mostdata = driver.find_elements_by_class_name('gvgMSe.gJYnHB')
    for most in mostdata:
        most = most.text.replace(',','')
        most = most.text.replace(',','')
        data.append(most)

    last7dsales = driver.find_elements_by_class_name('fGpHsy.kpsxyE')
    for last in last7dsales:
        last = last.text.replace(',','')
        last7day.append(last)

I didn’t check correctness of the rest of your code, but clicking the next button should work now

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement