I'm trying to locate a link using Selenium Webdriver. I don't wanna locate it by link text, only the actual link which is typed in . This can be done by using Selenium's find element by xpath - method, but what is the syntax when I only know the starting of that href text, not the whole text?
I guess I'm seaching for xpath link locator with some sort of starts with-method. I have no code ready on this.
Using XPath- starts-with method, we can write the Java code along with the dynamic XPath location as: findElement(By. xpath("//*[starts-with(@id,'lst')]"));
Go to the First name tab and right click >> Inspect. On inspecting the web element, it will show an input tag and attributes like class and id. Use the id and these attributes to construct XPath which, in turn, will locate the first name field.
Types of X-path The key characteristic of XPath is that it begins with the single forward slash(/) ,which means you can select the element from the root node.
To identify the element with xpath, the expression should be //tagname[@attribute='value']. To identify the element with xpath, the expression should be //tagname[@class='value']. There can be two types of xpath – relative and absolute.
You can use the start-with
in xpath to locate an attribute value that starts with a certain text.
For example, assume you have the following link on the page:
<a href="mylink_somerandomstuff">link text</a>
Then you can use the following xpath to find links that have an href that starts with 'mylink':
//a[starts-with(@href, "mylink")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With