Taking a simple example of facebook,
You want to locate the Email or Phone.
Let's Inspect the element and see what it has for us.
<input type="email" class="inputtext" name="email" id="email" data-testid="royal_email">
Here we have many attributes to use such as type, class, name, id , data-testid.
You can directly use ID using
As you want to use the XPath lets see how to make use of relative Xpath.
the expression will come out to be as
which will be used as follows:
This way you can use relative Xpath to locate an element using an Attribute.
Hope this helps.