Common tricks

  • 30
    Jul

    Selecting drop down contents which auto-refresh on previous value selection in selenium

    Many a times our test selection impacts the value to be displayed in subsequent fields. eg. on selection the State as “Karnataka” the city drop down is refreshed to...

    Read More
  • 27
    Jun

    How to capture screenshot in Selenium webdriver

    package Screenshot; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class ScreenshootGoogle { @Test public void TestJavaS1() { WebDriver driver...

    Read More
  • 26
    Jun

    select random item from drop down in selenium

    public static void selectDropDownDataRandomly(WebElement webElement) { Select dropdown = new Select(webElement); dropdown.selectByIndex(randomNumber(dropdown.getOptions().size())); } // function to get random number between 0 to number public static int randomNumber(int number) {...

    Read More
  • 26
    Jun

    select drop down value by visible text / index value

    public static void selectDropDownByVisibleText(WebElement webElement, String visibleText) { Select dropdown = new Select(webElement); if(visibleText ==null ||visibleText.isEmpty()){ return; } dropdown.selectByVisibleText(visibleText); System.out.println(“Value selected:{} “, visibleText); } ======================================================= public static void selectDropDownByIndex(MCWebElement...

    Read More
  • 26
    Jun

    check if a checkbox is checked in selenium webdriver

    package SeleniumPractice; import java.text.ParseException; 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.openqa.selenium.interactions.Actions; import org.testng.Assert; import org.testng.annotations.Test; public class AddCookiesInSelenium { WebDriver driver; @Test...

    Read More
  • 26
    Jun

    scroll a long web page in selenium webdriver

    package SeleniumPractice; import java.text.ParseException; 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.openqa.selenium.interactions.Actions; import org.testng.Assert; import org.testng.annotations.Test; public class AddCookiesInSelenium { WebDriver driver; @Test...

    Read More
  • 26
    Jun

    drag and drop with selenium webdriver

    package SeleniumPractice; import java.text.ParseException; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.testng.Assert; import org.testng.annotations.Test; public class DragAndDropInSelenium { WebDriver driver; @Test public void...

    Read More
  • 26
    Jun

    working with menus in Selenium (mouseover and click on link)

    package SeleniumPractice; import java.text.ParseException; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.testng.annotations.Test; public class Workingwithmenus { WebDriver driver; @Test public void enterText() throws InterruptedException, ParseException...

    Read More
  • 26
    Jun

    add custom cookie with selenium webdriver

    package SeleniumPractice; import java.text.ParseException; import java.util.Set; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; public class AddCookiesInSelenium { WebDriver driver; @Test public void enterText() throws InterruptedException, ParseException...

    Read More
  • 08
    Jan

    Screen orientation in Mobile browsers

    //Changing screen Orientation to LANDSCAPE. driver.rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE); //Changing screen Orientation to PORTRAIT. driver.rotate(org.openqa.selenium.ScreenOrientation.PORTRAIT);   reference

    Read More