Hi Rohan, steps to scroll a webpage in Mozilla Firefox using Selenium:
- Launch Eclipse IDE and open the existing package. For eg. "pageObjects"
- Right click on the "src" folder and create a new Class File "Scroll_Test" from New >Class.
- Now, write the below shown script in your editor and save the test script:
package pageObjects;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Scroll_Test {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver","C:\\Users\\Abha_Rathour\\Downloads\\ExtractedFiles\\geckodriver-v0.24.0-win64\\geckodriver.exe" );
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette",true);
WebDriver driver= new FirefoxDriver(capabilities);
driver.navigate().to("https://www.edureka.co");
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("scrollBy(0, 4500)");
Thread.sleep(3000);
driver.close();
}
}
Upon execution, the above test script will launch the Firefox browser and automate all the test scenarios.