Showing posts with label Selenium 3. Show all posts
Showing posts with label Selenium 3. Show all posts

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