0
votes

I'm new to Selenium Webdriver. I have been using Firebug & Firepath to generate xpath (copy pasting the given xpath) for the web elements, but I am facing problems when using such xpaths(Such as "Xpath cannot be evaluated into an web elemnt").

Please help me with the below example of xpath of a Webelement to create a flexible & generic xpath:

<input type="text" maxlength="15" length="40" value="" name="ST_ACK_NUM"/>
1
Don't use the absolute xpath you get from firebug, a minor change to the html may make the xpath no longer work. - Code Enthusiastic
Hi. It's a very bad idea using the xpath generated by firepath because firepath generates xpath based on positions. Check out this blog guru99.com/accessing-links-tables-selenium-webdriver.html provides some good info on xpath. - Vinay

1 Answers

3
votes

Like the people say in the comments it is better to create a more relative path to your elements. Maybe you can post some more input so the XPath can be created more efficiently.

To get the input with a absolute XPath you can do:

 //input[@name='ST_ACK_NUM']

Above XPath will search the complete source to all <input> elements where attribute name equals the value ST_ACK_NUM

When you look at your source maybe you can adjust the XPath and add more dependencies. For example if your input looks like:

 <div class="DivClass">
   <form name="FormName">
     <input type="text" maxlength="15" length="40" value="" name="ST_ACK_NUM"/>
   </form>
 </div>

You could use a XPath like:

 //div[@class='DivClass']/form[@name='FormName']/input[@name='ST_ACK_NUM']

This will also find the <input> element, but with a lot more dependencies.