Posts

Showing posts from June, 2019

How to handle calendar or date picker using dynamic XPATH?

Image
Most of the times selecting a particular date from a date picker is a tedious job. We can easily automate this scenario with the help of dynamic XPATH. AUT : https://www.spicejet.com/ Test Steps : Navigate to  https://www.spicejet.com/ Enter Departure City Enter Arrival City Click on "Depart Date" date picker and select an appropriate date of departure Click on 'Flights' icon to view the available flights Test Script : package seleniumwebdriverbestpractices; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class HandleCalendarUsingDynamicXPATH { static WebDriver driver; public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub System.setProperty("webdriver....

How to do Page Scroll Using JavascriptExecutor?

package seleniumwebdriverbestpractices; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; public class ScrollPage { WebDriver driver; @Test public void scrollingPageTest() throws Throwable{ System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\drivers\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); // driver.get("https://www.spicejet.com/"); driver.get("https://www.w3schools.com/"); driver.manage().window().maximize(); JavascriptExecutor js = (JavascriptExecutor)driver; // Scroll Down js.executeScript("window.scrollBy(0,1000)", ""); Thread.sleep...