我想向下滚动我的网页。我应该在Selenium中使用什么Java命令?
答案 0 :(得分:0)
向下滚动网页不是有效的用例,可以对其进行验证,或许您希望向下滚动以在Viewport内引入 WebElement 进行交互用它。为此,您可以使用executeScript()
方法,如下所示:
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", element);
答案 1 :(得分:0)
使用以下代码并尝试
JavascriptExecutor js = (JavascriptExecutor) driver;
// Launch the application
driver.get("http://demo.guru99.com/test/guru99home/");
//This will scroll the web page till end.
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
答案 2 :(得分:0)
请参考下面的代码:
1)使用Action类****
WebDriver driver = new ChromeDriver();
//Creating an object 'action'
Actions action = new Actions(driver);
//open SoftwareTestingMaterial.com
driver.get(Site URL); // Give site URL as name of the web page
//sleep for 3secs to load the page
Thread.sleep(3000);
//SCROLL DOWN
action.sendKeys(Keys.PAGE_DOWN).build().perform();
Thread.sleep(3000);
//SCROLL UP
action.sendKeys(Keys.PAGE_UP).build().perform();