Locating elements

While humans are intuitively good at figuring out what to do on a web page, automated tests need very specific instructions. Before interacting with an element, you must locate it using an element locator. Selenium / WebDriver provides a variety of locators and MuseIDE supports all of them.

Thanks to the immense popularity of Selenium/WebDriver, there are many resources that can help you understand how to choose the right locator for the element. Here are a few that may help you. These may reference specific Selenium/WebDriver code APIs or product features that won't apply to MuseIDE, but the concepts will. I will show some examples both in this and later sections of the tutorial.

The expression format for locating an element provides two parameters: the type of locator and a target string that tells the locator what to look for:

<type:"target">

Enter text

Continuing to build the test: after going to the site, I want to perform a search.

To enter text in a field, use a Send Keys step. It takes two parameters - the text to be typed and a locator for the element that should receive the keystrokes.

In this example, I enter "giraffe" into the search field, which I have located using the element's id attribute.

test1-search-field.png

Submit the search

Next I want to submit the search by clicking on the search button. This button does not have an id attribute, so I will use an XPath selector.

test1-submit-search.png

Verify the result

Finally, I want to verify we have landed on the right page. The verify step evaluates it's parameter and fails if it is not true. I'll use a simple technique - checking the page title matches what I expect. Extract the page title from the browser and compare it like this:

test1-verify-result.png

If the verify fails, the failure will be recorded in the event log and the test will be considered a failure.

Next: Data-driven testing.

Return to Tutorials page