JS实现Selenium下拉滚动条到指定元素

1、以下只适合IE、Firefox:

1 el=browserCore.findElement(By.xpath(xpath));
2 javaScriptExecutor.executeScript("arguments[0].scrollIntoView();", el);  
3 javaScriptExecutor.executeScript("arguments[0].scrollIntoView(true);", el);
4 pause(stepInterval);

2、以下IE、Firefox、Chrome都适用:

1 //将内嵌滚动条拉到页面最底端,才能看到的元素
2 javaScriptExecutor.executeScript("document.getElementsByClassName('"+className+"')[0].scrollTop=100000");
3 pause(stepInterval);
posted @ 2018-01-08 09:47  helenqueen  阅读(2175)  评论(0编辑  收藏  举报