These are probably the most commonly used commands for building test.
open opens a page using a URL.
click/clickAndWait performs a click operation, and optionally waits for a new page to load.
verifyTitle/assertTitle verifies an expected page title.
verifyTextPresent verifies expected text is somewhere on the page.
verifyElementPresent verifies an expected UI element, as defined by its HTML tag, is present on the page.
verifyText verifies expected text and it’s corresponding HTML tag are present on the page.
verifyTable verifies a table’s expected contents.
waitForPageToLoad pauses execution until an expected new page loads. Called automatically when clickAndWait is used.
waitForElementPresent pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.
Here is an alternative to using contains text() in xpath command
script type="text/javascript"
try {
var pageTracker = _gat._getTracker("UA-222222-3");
pageTracker._trackPageview();
} catch(err) {}script
In this example I will tell you how you can use selenium’s getXpathCount and then validating if the count is matching with the expected count:
In the below example we are getting the xpath count of the element //span[@id='ctl00'] and then storing the count to CountNo. Then outputting the result to NUnit console.
decimal CountNo = selenium.GetXpathCount("//span[@id='ctl00']");
Console.WriteLine(CountNo);
To close the Firefox browser windows after Selenium test has run the solution is to call the Selenium TeardownTest() method.
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
That closes down all the browser windows successfully.
selectWindow ( windowID )
Selects a popup window using a window locator; once a popup window has been selected, all commands go to that window. To select the main window again, use null as the target.
Window locators provide different ways of specifying the window object: by title, by internal JavaScript “name,” or by JavaScript variable.
The difference between a command and its AndWait alternative is that the regular command (e.g. click) will do the action and continue with the following command as fast as it can, while the AndWait alternative (e.g. clickAndWait) tells Selenium to wait for the page to load after the action has been done.