Skip to content
Advertisement

Python Selenium – How To Click a Non Button Element [closed]

Ive Been Trying to Click a Button on https://blockchain.coinmarketcap.com/chain/bitcoin But With No Success (Shown in photo below). I Couldn’t even get the element I wanted to click. If someone can help me find the element and how to click it, it would be very helpful to me. Thanks in advance. The Button Im trying to click is the page 2 button

Advertisement

Answer

First you need to wait until the element is presented on the page, then scroll to it and then click on it.
I tried to do it as following:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

pagination_2_el_xpath = '//li[@class="ant-pagination-item ant-pagination-item-2"]'

pagination_2_el = wait.until(EC.presence_of_element_located((By.XPATH, pagination_2_el_xpath)))

time.sleep(0.1)

actions = ActionChains(driver)
actions.move_to_element(pagination_2_el).perform()

pagination_2_el.click()

Also it’s better to click on “next page” button so you can use this:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

next_page_css = 'li.ant-pagination-next'

next_page = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, next_page_css)))

time.sleep(0.1)

actions = ActionChains(driver)
actions.move_to_element(next_page).perform()

next_page.click()
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement