Python Selenium - 如何在分页中单击不是按钮的元素 (<a href="#">›</a>)

问题描述 投票:0回答:1

我正在尝试使用 Selenium 单击“https://openreview.net/group?id=NeurIPS.cc/2022/Conference#accepted-papers”的下一页按钮 Pagination 检查时,导航到下一页的“按钮”是

<a href="#">...</a>

URL = "https://openreview.net/group?id=NeurIPS.cc/2022/Conference#accepted-papers"

driver = webdriver.Chrome()
driver.get(URL)

WebDriverWait(driver,15)

for i in range(5):
    first_paper = driver.find_element("xpath","/html/body/div/div[3]/div/div/main/div/div[3]/div/div[2]/div[2]/ul/li[1]/h4/a[1]").text
    print(first_paper)


    element = driver.find_element("xpath","/html/body/div/div[3]/div/div/main/div/div[3]/div/div[2]/div[2]/nav/ul/li[13]/a")
    element.click()

    WebDriverWait(driver,5)

第二次点击页面似乎无法点击(selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (792, 1230.).)。我正在打印每页的第一篇论文以确保它有效。

我也试过这个没有成功:

for i in range(3):

    first_paper = driver.find_element("xpath","/html/body/div/div[3]/div/div/main/div/div[3]/div/div[2]/div[2]/ul/li[1]/h4/a[1]").text
    print(first_paper)

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable(("xpath","/html/body/div/div[3]/div/div/main/div/div[3]/div/div[2]/div[2]/nav/ul/li[13]/a"))).click()

    WebDriverWait(driver,10)
selenium-webdriver
1个回答
0
投票

尝试使用以下代码浏览页面:

    # Find the pagination list using its CSS selector
    pagination_list = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.CSS_SELECTOR, "ul.pagination")))

    # Find all the pagination numbers 
    pagination_numbers = pagination_list.find_elements_by_tag_name("a")
    
    # Iterate through pagination number and click 
    for page_number in pagination_numbers:
        # Click on the pagination number
        page_number.click()
        
        # Wait for the new page to load before proceeding
        WebDriverWait(driver, 15).until(EC.staleness_of(page_number))
© www.soinside.com 2019 - 2024. All rights reserved.