Locating elements

While humans are intuitively good at figuring out what to do on a web page, automated tasks 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:


Enter text

Continuing to build the task: 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.


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.


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:


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

Next: Data-driven tasks.

Return to Tutorials page