Javatpoint Logo
Javatpoint Logo

Locating Strategies- (By XPath- Using contains())

In this section, you will learn how to locate a particular web element by XPath- Using contains() method.

"contains()" is used to identify an element, when we are familiar with some part of the attributes value of an element.

Let us consider an example in which we will try to locate the Google Search Engine Text box by XPath- Using contains() method.

Follow the steps given below to locate the textbox provided on the home page of Google Search Engine.

  • Open URL: https://www.google.co.in/ in your Firefox browser
  • Right click on the Textbox on the sample web page and select Inspect Element
Locating Strategies- By XPath- Using contains()
  • It will launch a window containing all the specific codes involved in the development of the textbox.
Locating Strategies- By XPath- Using contains()
  • Take a note of its id Attribute.
Locating Strategies- By XPath- Using contains()

The syntax for locating elements through XPath- Using contains() method can be written as:

or

Using XPath- conatins() method, we can write the Java code along with the dynamic XPath location as:







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA