How to use regular expressions in IDE selenium plug in with example

Using Regular Expression Patterns with selenium
Regular Expression Patterns is another matching text pattern which describe text pattern to selenium. There are another two matching text patterns(Globbing Patterns and Exact Patterns) are available but this is the most powerful matching text pattern from all these three. Regular Expression Pattern describes expected text
pattern to selenium using some special characters rather than specifying that exact text. You need to use text "regexp:" at the beginning of your text pattern to describe it as a Regular Expression and then you have to write your expression. Example "link=regexp:Your_expression"

Let we learn it with some examples so that you can understand it better.

Using Regular Expression Pattern to click on link in selenium
New Test
CommandTargetValue
openhttp://www.software-testing-tutorials-automation.com/
clickAndWaitlink=regexp:.*bo.* M.*

In above example, "clickAndWait" command will click on "About Me" link on home page.In "link=regexp:.*bo.* M.*", word "regexp:" describes that this is regular expression and ".*bo.* M.*" is the expected text pattern for link "About Me".

Using Regular Expression Pattern to select label from drop down in selenium
New Test
CommandTargetValue
openhttp://www.ebay.com
selectgh-catlabel=regexp:.*am.* P.*

In this example, "select" command will select "Cameras & Photos" from the search categories drop down on ebay store.

Using Regular Expression Pattern verify dynamic text pattern
New Test
CommandTargetValue
openhttp://www.software-testing-tutorials-automation.com/2013/06/matching-text-patterns-globbing.html
verifyTextPresentregexp:Friday.*[0-9]{4}
Here "verifyTextPresent" will verifies the text "Friday, 7 June 2013" on page. In this regular expression, [0-9]{4} describes the 1 to 4 digits (for year).

1 comment:

  1. hi there, I wonder if you could help me... Complete noob using Selenium webdriver.

    I am trying to find a regex I can use for this: input id="chk_Compare260809-b57edc22-1439-4865-8514-c760db9f24ff" type="checkbox" onclick="AddComparisonToSessionSearch('260809', 'Atlantis The Palm', 'b57edc22-1439-4865-8514-c760db9f24ff', this.checked, 'PackageSearch') " value="false" name=""> I am using command: verifyElementPresent but can't figure out anything to use with it.....

    ReplyDelete