使用Action类的话报 java.lang.IllegalArgumentException: Key Down / Up events only make sense for modifier keys.(使用Action模拟键盘操作点击↓键,或者点击space键,也是可以达到浏览器滚动条下滑的效果)
这样写//巧用scroll bar
/**
* This method is used to scroll the page scroll bar to the top position
*/
public static void scrollTop() {
((JavascriptExecutor) driver).executeScript("jQuery(document).scrollTop(0)");
}
/**
* This method is used to scroll the page scroll bar to the bottom position
*/
public static void scrollBottom() {
((JavascriptExecutor) driver)
.executeScript("jQuery(document).scrollTop(jQuery(document).height())");
}
/**
* 用于特殊操作控制浏览器scroll bar位置
*/
public static void scrollDown(int i) {
String a = "jQuery(document).scrollTop(" + i + ")";
((JavascriptExecutor) driver).executeScript(a);
}