Hello @User,
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
driver.findElement(By.Id("email"));
As you want to use the XPath lets see how to make use of relative Xpath.
the expression will come out to be as
//input[contains(@id,'email')]
which will be used as follows:
driver.findElement(By.xpath("//input[contains(@id,'email')]"));
This way you can use relative Xpath to locate an element using an Attribute.
Hope this helps.