Sunday, December 17, 2017

Sending keys in selenium


In Selenium, we are send specific keys from the keyboard like Enter or F2 on WebElement using import org.openqa.selenium.Keys as shown below:


import org.openqa.selenium.Keys

WebElement.sendKeys(Keys.ENTER)

Below is the list of enum constants defined for enum Keys, which we can send on an element in selenium:


ADD 
ALT 
ARROW_DOWN 
ARROW_LEFT 
ARROW_RIGHT 
ARROW_UP 
BACK_SPACE 
CANCEL 
CLEAR 
COMMAND 
CONTROL 
DECIMAL 
DELETE 
DIVIDE 
DOWN 
END 
ENTER 
EQUALS 
ESCAPE 
F1 
F10 
F11 
F12 
F2 
F3 
F4 
F5 
F6 
F7 
F8 
F9 
HELP 
HOME 
INSERT 
LEFT 
LEFT_ALT 
LEFT_CONTROL 
LEFT_SHIFT 
META 
MULTIPLY 
NULL 
NUMPAD0 
NUMPAD1 
NUMPAD2 
NUMPAD3 
NUMPAD4 
NUMPAD5 
NUMPAD6 
NUMPAD7 
NUMPAD8 
NUMPAD9 
PAGE_DOWN 
PAGE_UP 
PAUSE 
RETURN 
RIGHT 
SEMICOLON 
SEPARATOR 
SHIFT 
SPACE 
SUBTRACT 
TAB 
UP 
ZENKAKU_HANKAKU 
For further details, please see the Page: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/Keys.html

Sunday, September 24, 2017

Arrays in Java basics for selenium


1. We can assign value to an element in array as shown below:

testing[3] = 43; or all the elements can be defined in a go like shown below:
int[] testing1= {10,20,30,40,50,60,70,80,90,100};

2. We can extract all the values in an array using for each loop as shown below:

 int[] testing1 = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
 for (int test : testing1) {
     System.out.println(test);
 }

3. The same information can be extracted using for loop can be found as shown below:

for (int i = 0; i < testing1.length; i++) {
     System.out.println(testing1[i]);
 }

4. Using length property, we can find the size of any array


e.g. System.out.println(testing1.length)

4. We can pass an array as a parameter to a method, and also return value from a method:

5. We can sort an array in ascending order using sort();

Arrays.sort(testing1);

6. We can fill values in all the array elements using fill() menthod 
Arrays.fill(testing1, 385);

7. We can compare two arrays using arrays.equals

boolean isArrSame = Arrays.equals(testing1, testing);
System.out.println(isArrSame);

Sunday, July 23, 2017

Code to open firefox with selenium 3.4 using GeckoDriver 1.8


package test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class testing {

    public static void main(String[] args) throws InterruptedException {
 // Download the geckodriver based on the firefox if it is 32 bit or 64
 // bit installed in the machine
 // Save the driver and provide path of the exe for geckodriver
 System.setProperty("webdriver.gecko.driver", "E:\\Selenium\\geckodriver-v0.18.0-win64\\geckodriver.exe");
 // define the capabilities of firefox browser with marionette set as true
 DesiredCapabilities capabilities = DesiredCapabilities.firefox();
 capabilities.setCapability("marionette", true);
 // create an instance of firefox driver
 WebDriver driver = new FirefoxDriver(capabilities);
 driver.get("http://www.rediff.com");
 driver.quit();
    }
}