【问题标题】:I can't manage to get to scroll down in Selenium using python我无法使用 python 在 Selenium 中向下滚动
【发布时间】:2021-02-05 08:18:13
【问题描述】:

我正在尝试向下滚动页面,因为在我单击一次按钮后,帮助元素与下一页按钮重叠,因为页面向下移动。 下一个按钮位于匹配历史表上方。 我尝试使用

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

什么都没有发生, 然后我尝试使用

element=driver.find_element_by_xpath("//table[@class='Table flx-sm dir-r-sm jst-s-sm flx-nw-sm ialgn-st-sm']")
actions = ActionChains(driver)
actions.move_to_element(element).perform()

它给了我错误:MoveTargetOutOfBoundsException: Message: (1009, 835) is out of bounds of viewport width (1536) and height (750)

我尝试过使用

html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.END)

什么都没有动。这是我正在尝试的代码和网站。(我也尝试使用 Chrome,但结果相同)

driver = webdriver.Firefox()
url2="https://app.senpai.gg/lol/profile/eune/Primm"
driver.get(url2)
button = driver.find_element_by_xpath('/html/body/div[2]/div/div/section/div/section/main/div[1]/div[1]/div[6]/div/div[1]/div[2]/div/button[2]')
    time.sleep(10)
while true:
    if(button.is_enabled() and button.is_displayed()):
        button.click();
    else:
        break;

【问题讨论】:

    标签: python selenium scroll webdriver


    【解决方案1】:
    $('[class="el-main"]').scrollBy(0,$('[class="el-main"]').scrollHeight)    
    

    你必须找到滚动元素,然后在上面使用scrollBY

    driver.execute_script("$('[class=\"el-main\"]').scrollBy(0,$('[class=\"el-main\"]').scrollHeight);")
    

    如果你得到 $ 未定义使用:

    driver.execute_script("arguments[0].scrollBy(0,arguments[0].scrollHeight);", driver.find_element_by_class_name('el-main'))
    

    你也可以这样做:

    driver.get(url2)
    
    driver.find_element_by_class_name('el-main').click()
    
    driver.find_element_by_css_selector("body").send_keys(Keys.END)
    

    首先你必须通过点击滚动来获得焦点,然后在 body 上发送 END 键

    寻找定位器:

    【讨论】:

      猜你喜欢
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多