Selenium Commands

Basic Commands

There are three types of commands: Actions, Assertions, and Waits.

Actions – functional actions performed on the web application under test in the browser. For example, filling in fields, clicking a button, and so on;

Assertions – checks performed on the page under test. For example, checking that a particular form field has the specified value, or checking the window title;

Waits – setting up how long Selenium will wait, and for which event (waiting for a page to load, for ajax, and so on).

Checks in a test. Selenium uses 2 main kinds of checks:

assert* - an "assertion" is a check that, if it fails, makes the test fail with an error.

verify* - a "verification" is a check that, if it fails, lets the test keep running
"assert" checks are used for critical checks: if they fail, there is no point in continuing the test at all. "verify" checks are used for non-critical elements.

  • verifyLocation / assertLocation – checks the current URL of the browser window (|verifyLocation|url_needed||)
  • verifyTitle / assertTitle – checks the window title (|verifyTitle|title_needed||)
  • verifyValue / assertValue – checks that a form field has the specified value (|verifyValue|field|value_needed|)
  • verifyTextPresent / assertTextPresent – checks that the page text contains the specified text (|verifyTextPresent|text_needed||)
  • verifyElementPresent / assertElementPresent – checks that an element is present on the current page (|verifyElementPresent|element_needed||)

List of commands and what they mean

click - the most popular command: click on an element. It clicks at the center.

clickAndWait - click and wait. If the click triggers loading of another page, the waitForPageToLoad command will be executed automatically.

waitForPageToLoad - wait until the page has loaded;

store* - save the value of an element

wait* - wait for some event, for example for an element to appear

open – open a page in the browser at a given address.

click – perform a click on a page element.

type – enter a value into a text field on the page. Usage example – selenium.Type("id_TextField_1", "test");

select – choose a value from a drop-down list. Usage example – selenium.select (TimeEntryTaskList, "Activity1") .

selectWindow – switch focus to another window. Usage example – selenium.selectWindow("id_dashboard");

getTitle – returns the title of the current page. Usage example – selenium.GetTitle();

getValue – returns the value of a page element. Usage example – selenium.GetValue("id_TextBox1");

goBack – go back to the previous page. Usage example – selenium.GoBack();

close – close the current window. Usage example - selenium.Close().

verifyLocation / assertLocation – check the address of the current page.

getAlert - emulates clicking the OK button (the alert window does not appear)
verifyAlert(pattern) - checks that the text matches the pattern and clicks OK
assertAlert - checks that the text matches the pattern (if not, the test fails) and clicks OK