在做selenium web自动化的时候,经常会遇到一个这样的场景,某些元素在页面的底部,需要滚动页面使其可见。可以借助js来实现该场景
代码(python)
def scroll_element(self, driver, element): # 滑动滚动条到某个指定的元素 js4 = "arguments[0].scrollIntoView();" driver.execute_script(js4, element)
代码(java)
public static void scrollToSpecifiedElement(WebDriver driver, WebElement element){ Point location = element.getLocation(); String s = "window.scrollBy(" + location.getX() + "," + location.getY() + ")"; ((JavascriptExecutor) driver).executeScript(s);}
留言与评论(共有 0 条评论) “” |