当浏览器中有多个具有使用python硒的滚动条的窗口时,如何向下滚动

时间:2019-05-04 01:43:02

标签: python selenium selenium-webdriver selenium-chromedriver webautomation

因此,单击按钮后,将弹出一个弹出窗口(如图所示),它具有2个带有滚动条的元素。我想向下滚动主要的右侧元素。

browser.execute_script("window.scrollBy(0, 10000)","")

这行代码不起作用。它没有引发错误,但是没有任何作用。

1 个答案:

答案 0 :(得分:2)

这是在每一行上滚动和执行操作的逻辑。

driver.find_element_by_xpath("(//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item])[last()]").location_once_scrolled_into_view
time.sleep(2)
driver.find_element_by_xpath("(//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item])[last()]").location_once_scrolled_into_view

# get the number of rows
rows = driver.find_elements_by_xpath("//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item]")
# now you can access each row here in for loop
for rowNumber in range(len(rows)):
    # scroll to the row
    driver.find_element_by_xpath("(//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item])[" + str(rowNumber+1) "]").location_once_scrolled_into_view
    # if you want to click on the button (+) for that user
    driver.find_element_by_xpath("((//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item])[" + str(rowNumber+1) "]//span[@class='ui_button_icon'])[1]").click()
    # you can use row element for any action with in the row
    row.xxxxxx