如何使用groovy和webdriver在JavaScript中使用Firefox来触发鼠标滚轮事件?

时间:2013-12-17 17:30:34

标签: selenium groovy selenium-webdriver

有没有人知道如何使用Web驱动程序和groovy来触发鼠标滚轮事件。我已经附上了我希望能够向下滚动100像素的代码,任何人都可以显示能够做到这一点的代码吗?

package Check
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

class Fourth {
    //FirefoxDriver driver;

    static main(args) {
        def FirefoxDriver driver = new FirefoxDriver();
        driver.get("https://www.google.co.uk/search?q=dreams")
        //Code to allow web page to be scrolled needs to be inserted here
        sleep(5000);
        driver.quit();
        }

}

1 个答案:

答案 0 :(得分:0)

我可以使用JavaScript执行器向下滚动页面,我已经发布了与groovy相关的代码,享受!

package Check
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.JavascriptExecutor;

class Fourth {
    //FirefoxDriver driver;

    static main(args) {
        def FirefoxDriver driver = new FirefoxDriver();
        driver.get("https://www.google.co.uk/search?q=dreams")
JavascriptExecutor js = (JavascriptExecutor)driver;
                    js.executeScript("window.scrollTo(0,2000);");
                        sleep(5000);
        driver.quit();
        }

}