繁体   English   中英

无法点击按钮 Selenium

[英]Can't click on button Selenium

我在单击此页面上的“下一步”按钮时遇到问题:

https://www.govinfo.gov/app/collection/uscourts/district/alsd/2021/%7B%22pageSize%22%3A%22500%22%2C%22offset%22%3A%220%22%7D

我试过 xpath,css_selector 和没有骰子。 这是代码:

try:
        next_page = driver.find_element_by_xpath('//*[@id="collapseOne3578"]/div/span[1]/div/ul/li[4]')
        if next_page:   
                print('Trying to get next page')
                print(next_page)
                next_page.click()
        else:
            continue
except:
    break

我将变量放在 try 语句中,因为某些页面没有超过 500 的结果,因此没有下一步按钮。 如果我在语句之外定义变量,则代码会中断。

谢谢你的帮助

您使用了错误的定位器。
请试试这个:

next_page = driver.find_element_by_xpath('//li[@class="next fw-pagination-btn"]')

或这个

next_page = driver.find_element_by_css_selector('li.next.fw-pagination-btn')

在定位元素之前不要忘记添加等待,最好是期待条件。

尝试这个:

driver.find_element_by_xpath(".//ul[@class='pagination']/li/a[text()='Next']").click()

该元素不可见,因此我使用了:

next_page = WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,'//li[@class="next fw-pagination-btn"]')))
driver.execute_script('arguments[0].click()', next_page)

它奏效了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM