SeleniumCommands:
Selenium Server(selenium-server-standalone
-<version number>.jar) receives Selenium commands from your test program,
interprets them, and reports back to your program the results of running those
tests.
The RC server bundles Selenium Core and
automatically injects it into the browser. This occurs when your test program
opens the browser (using a client library API function). Selenium-Core is a
JavaScript program, actually a set of JavaScript functions which interprets and
executes Selenese commands using the browser’s built-in JavaScript interpreter.
The Server receives the Selenese commands from your
test program using simple HTTP GET/POST requests. This means you can use any
programming language that can send HTTP requests to automate Selenium tests on
the browser.
1. type(locator, value) : example :
selenium.type("//input[@id='username']", "ganeshapv_2004");
2. getValue(locator) : example : String username =
selenium.getAttribute("id=username");
3. getAtttribute(locator) example : String nameAttr
= selenium.getAttribute("id=username");
4. isEditable(locator)
if(selenium.isEditable("//input[@id='username']"))
{
System.out.println("Username text field is
Editable");
}else
{
System.out.println("Username text field is non
Editable");
}
1.Click(locator) example :
selenium.click("//button[@id='.save']");
Label Related Commands
1. getText (loocator) example : String userLabel =
selenium.getText("//label[@for='username']");
1.Click(Locator) example :
selenium.click("link=Forgot Password");
2. getText(Locator) example String lnkTest =
selenium.getText(“link=Forgot Password”);
CheckBox/Radio button Related Commands
1.check(Locator) -- Checks the CheckBox example :
selenium.check("//input[@id='persistent']");
2. uncheck(Locator) -- Unchecks the CheckBox example
: selenium.uncheck("//input[@id='persistent']");
3. isChecked (Locator) -- Returns whether a checkbox
is checked or unchecked.
Returns True, if a checkbox is checked.
Returns False, if a checkbox is unchecked.
Example : boolean checkStatus =
selenium.isChecked("//input[@id='persistent']");
System.out.println("Lnk Test
:"+checkStatus);
1. getSelectOptions (Locator) -- Gets all the list
items within a List Box
example : String[] options =
selenium.getSelectOptions("//select[@id='bm']");
for(int i=0;i<options.length;i++)
{
System.out.println("options
:"+options[i]);
}
2. select (locator, valueToSelect) -- Selects an
item in the List Box
example :
selenium.select("//select[@id='bm']", "August");
3. getSelectedLabel (locator) -- Returns Selected
Label
example : String selectedValue =
selenium.getSelectedLabel("//select[@id='bm']");
System.out.println("selectedValue:"+
selectedValue);
4. getSelectedIndex (locator) -- Gets option index
(option number, starting at 0) for selected option in the specified select
element.
Example : String selectedIndex =
selenium.getSelectedIndex("//select[@id='bm']");
System.out.println("selectedIndex
:"+selectedIndex);
5. getSelectedValue(locator) -- Gets option value
(value attribute) for selected option in the specified select element.
Example : String selectedVal =
selenium.getSelectedValue("//select[@id='bm']");
System.out.println("selectedVal
:"+selectedVal);
6. addSelection (locator,optionLocator) -- Add a
selection to the set of selected options in a multi- select element using an
option locator.
locator - an element locator identifying a
multi-select box
optionLocator - an option locator (a label by
default)
7. removeSelection ( locator,optionLocator ) --
Remove a selection from the set of selected options in a multi-select element
using an option locator.
locator - an element locator identifying a
multi-select box
optionLocator - an option locator (a label by
default)
8. isSomethingSelected (locator) -- Returns whether
a List Box is selected or not.
Returns True, if a List Box is selected.
Returns False, if a List Box is not selected.
Example : boolean elementSelected =
selenium.isSomethingSelected("//select[@id='bm']");
System.out.println("elementSelected
:"+elementSelected);
1. isText Present(pattern)
a. Return true if the text is present
b. You can give regular expression with test (Note:
It supports glob pattern)
Examples
boolean textAvailabel =
selenium.isTextPresent("Find a Partner");
System.out.println("text availability
:"+textAvailabel);
boolean textAvailabel1 =
selenium.isTextPresent("Find a Partner");
System.out.println("text availability
:"+textAvailabel1);
boolean textAvailabel2 =
selenium.isTextPresent("Find a *");
System.out.println("text availability
:"+textAvailabel2);
boolean textAvailabel3 =
selenium.isTextPresent("Find a *");
System.out.println("text availability
:"+textAvailabel3);
boolean textAvailabel4 =
selenium.isTextPresent("Find a ?art*");
System.out.println("text availability
:"+textAvailabel4);
No comments:
Post a Comment