Element with Certain Text Locator in WebDriverIO

<<Previous Post                          << Complete Tutorial>>                             Next Post>>

Element with Certain Text Locator in WebDriverIO

Element with Certain Text Locator is used to identify elements other than Anchor Element present on web page. Or Unlike Identify only Anchor Element, Element with certain Locator text can identify other elements present on page.

It is used by “element=”.

Note: – This Locator is rarely used but when it is used then the way it is used is explained below.

Pre-requisite: Have ‘Visual Studio Code’ IDE installed in your machine (Click here to install if not installed in your machine)

Here is the small Exercise to print Visible text of any random Element using Element with Certain Text Locator in WebDriverIO: –

Using Element with Certain Text Locator

First, I will demonstrate the exercise we need to perform to print Visible text of any random Element using Element with Certain Text Locator of WebDriverIO , followed by practically demonstrating the WebDriverIO Automation code for achieving it.

1)  Navigate to http://omayo.blogspot.com/

2) Identify the type of Element for PracticeAutomationHere text present on page.

3) Print text PracticeAutomationHere using Element with Certain Text Locator.

Practical Demonstration:

Following are the Steps to Perform above Exercise (i.e. print visible text “PracticeAutomationHere” of paragraph element using element with certain text Locator of WebDriverIO, using WebDriverIO Automation code in ‘Visual Studio Code’ IDE:

Pre-requisite: Download the Project from here (Click here to Download) and Unzip it.

1) Open Visual Studio Code on your system

2) Click on File and Select Open Folder. Select the project folder from the above-extracted ZIP file:

3) Expand ‘test’ from the Explorer, right click on the displayed ‘specs’ and select ‘New File’ option as shown below:

4) Give any name of the newly created file say “Element_with_Certain_Text_test.js” and copy the below-given code into the newly created file as shown below and save the file:

The following is the WebDriverIO sample code for printing visible text of button element from ‘Omayo.blogspot.com’ application:

You can understand this code, by reading the comments provided in the below code:

Copy the code from here:-

const assert = require('assert')
describe('print visible text using Tag Name locator',() => {
 it('should print visible text using Tag Name locator',() => {

5) Click on ‘wdio.conf.js’ to open in the IDE, and make sure the Test file name is updated properly in this file as shown below and save it:

6) Click on Terminal and Open New Terminal.

7) By Default, Powershell Terminal will open as shown below:

8) Run geckodriver.exe in the Powershell terminal as shown below to run Geckodriver in background.

If you don’t see anything, that means the geckodriver is running in the background.

9) Open Another Terminal in the same way we did in step 6 and run below command in terminal.

.\node_modules\.bin\wdio .\wdio.conf.js

Observe that the ‘Element_with_Certain_Text_test.js’ will get executed successfully, the Firefox Browser will launch and then Visible text of Para PracticeAutomationHere webpage gets Printed by WebDriverIO Automation code.WebDriverIO Automation code.

And also, the result will be displayed as ‘Passed’ in the terminal as shown below:

This is how we can print visible text of para element using Element with Certain Text Locator of WebDriverIO. I will explain handling other different UI elements on the webpages using WebDriverIO in the upcoming articles.

Next Steps:

> To learn more about WebDriverIO, continue to the next post (Click on Next Post link below)

> Check complete WebDriverIO Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Ajay Lunia 

Connect to me on LinkedIn (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                          << Complete Tutorial>>                             Next Post>>

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp