2013-12-17 94 views
1

有誰知道如何使用Web驅動程序和常規觸發鼠標滾輪事件。我已經附上了我希望能夠向下滾動100 pix的代碼,任何人都可以顯示能夠做到這一點的代碼?如何用JavaScript使用groovy和webdriver在Firefox中觸發鼠標滾輪事件?

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(); 
     } 

} 

回答

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(); 
     } 

} 
相關問題