Home » WebDriver Locating Strategies By CSS Sub-String Matches

WebDriver Locating Strategies By CSS Sub-String Matches

by Online Tutorials Library

Locating Strategies- (By CSS- Sub-String Matches)

In this section, you will learn how to locate a particular web element using CSS – Sub-String Matches Technique.

WebDriver provides an interesting feature of allowing partial string matches using ^, $ and*.

1. Starts with (^):

To select and locate a web element, we would use ^ which means ‘starts with’.

Follow the steps given below to locate the Textbox using partial string matching technique.

Locating Strategies- By CSS- Sub-String Matches

  • It will launch a window containing all the specific codes involved in the development of the Text box.

Locating Strategies- By CSS- Sub-String Matches

  • Take a note of its tag and id attribute.

Locating Strategies- By CSS- Sub-String Matches

The Java Syntax for locating a web element through CSS – Sub-String Matches Technique using ^ operator is written as:

Therefore, for locating the Text box on the sample web page we will use the input tag along with the id attribute:

Similarly, for locating the Submit button on the sample web page we will use the button tag along with the id attribute:

We have created a sample script for you to get a better understanding of how to locate a web element through CSS – Sub-String Matches Technique using ^ operator.

2. Ends with ($):

To select and locate a web element, we would use $ which means ‘ends with’.

Follow the steps given below to locate the Textbox using partial string matching technique.

Locating Strategies- By CSS- Sub-String Matches

  • It will launch a window containing all the specific codes involved in the development of the Text box.

Locating Strategies- By CSS- Sub-String Matches

  • Take a note of its tag and id attribute.

Locating Strategies- By CSS- Sub-String Matches

The Java Syntax for locating a web element through CSS – Sub-String Matches Technique using $ operator is written as:

Therefore, for locating the Text box on the sample web page we will use the input tag along with the id attribute:

Similarly, for locating the Submit button on the sample web page we will use the button tag along with the id attribute:

We have created a sample script for you to get a better understanding of how to locate a web element through CSS – Sub-String Matches Technique using $ operator.

3. Contains (*):<

To select and locate a web element, we would use * which means ‘sub-string’.

Follow the steps given below to locate the Textbox using partial string matching technique.

Locating Strategies- By CSS- Sub-String Matches

  • It will launch a window containing all the specific codes involved in the development of the Text box.

Locating Strategies- By CSS- Sub-String Matches

  • Take a note of its tag and id attribute.

Locating Strategies- By CSS- Sub-String Matches

    The Java Syntax for locating a web element through CSS – Sub-String Matches Technique using * operator is written as:

    Therefore, for locating the Text box on the sample web page we will use the input tag along with the id attribute:

    We can also use ‘contains()’ in place of * operator

    We have created a sample script for you to get a better understanding of how to locate a web element through CSS – Sub-String Matches Technique using $ operator.

You may also like