如何用硒按下按钮



我正试图按下一个具有以下检查代码的按钮:

<button title="Page 2" class="StyledButton-c11n-8-31-0__wpcbcc-0 inbMjV PaginationButton-c11n-8-31-0__si2hz6-0 bcxbxh">2</button>

我试着定位按钮,但它不起作用:

driver.find_element_by_xpath('//*[@title="Page 2"]').click()

要单击该按钮,首先需要将该元素滚动到视图中
所以请尝试这样的方法:

from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_xpath('//*[@title="Page 2"]')
actions = ActionChains(driver)
actions.move_to_element(element).perform()

之后你应该可以点击

element.click()

试试这个xpath//*[@title="第2页"]。双引号可能导致问题

最新更新