硒:无法在搜索结果中单击“下一页”

时间:2020-10-02 23:06:05

标签: python-3.x selenium selenium-chromedriver

我正尝试在bing.com的结果页面上单击“下一步”按钮。我尝试了三种方法,但似乎无法使其正常工作。我尝试过:

next_page = driver.find_elements_by_class_name('sb_pagN sb_pagN_bp b_widePag sb_bp ')
next_page = driver.find_element_by_xpath("//a[@title='Next page']")
next_page = driver.find_element_by_xpath("//a[@h='ID=SERP,5502.1']")

next_page.click()

1 个答案:

答案 0 :(得分:1)

bool operator()(const cGuiRenderObject& aObjectA, const cGuiRenderObject& aObjectB) const;

一种通过css_selector始终查找下一个元素的动态方法。

driver.get("https://bing.com")
send = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#sb_form_q")))
send.send_keys("Town")
send.submit()

导入

next_page=WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#b_results > li.b_pag > nav > ul > li:last-child")))
next_page.click()