首页 > 代码库 > java selenium webdriver处理JS操作窗口滚动条
java selenium webdriver处理JS操作窗口滚动条
未经作者允许,禁止转载!!!
java selenium webdriver处理JS操作窗口滚动条
java selenium webdriver处理JS操作窗口滚动条
import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class JS20161212 { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub System.setProperty("webdriver.chrome.driver","C:\\Training\\Automation\\Software\\drivers\\chromedriver_win32\\chromedriver.exe"); WebDriver driver=new ChromeDriver(); driver.get("https://www.hao123.com/"); driver.manage().window().maximize(); Thread.sleep(2000); JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("scrollTo(0,10000)");----------------------------------------------向下拉到底 Thread.sleep(2000); js.executeScript("scrollBy(0, 0-document.body.scrollHeight *99/100)");--------------向上拉到顶 Thread.sleep(2000); js.executeScript("scrollTo(0,100000)");---------------------------------------------向下拉到底 Thread.sleep(2000); js.executeScript("scrollTo(0,1)");--------------------------------------------------向上拉到顶 Thread.sleep(2000); js.executeScript("scrollTo(0,1000)"); Thread.sleep(2000); js.executeScript("scrollBy(0, 0-document.body.scrollHeight *1/2)");-----------------拉到中间 Thread.sleep(2000); js.executeScript("scrollBy(0, 0-document.body.scrollWidht *1/2)");------------------左右拉到中间 // ((JavascriptExecutor)driver).executeScript("scrollTo(0,10000)");----------------精简后的代码 // Thread.sleep(2000); // ((JavascriptExecutor)driver).executeScript("scrollTo(0,1)"); } }
java selenium webdriver处理JS操作窗口滚动条
java selenium webdriver处理JS操作窗口滚动条
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。