0

http://newtours.demoaut.com/mercuryregister.php Find xpath for first name and last name is very difficult. How Xpath can be used if
there is no id , tag or class available.

  Contact Information

      </tr>
      <tr> 
        <td align="right"><font face="Arial, Helvetica, sans-serif" size="2"><b>First 
          Name: </b></font></td>
        <td> 
          <input maxlength="60" name="firstName" size="20">
        </td>
      </tr>
      <tr> 
        <td align="right"><font face="Arial, Helvetica, sans-serif" size="2"><b>Last 
          Name: </b></font></td>

        <td> 
          <input maxlength="60" name="lastName" size="20">
        </td>
      </tr>
      <tr> 

1 Answer 1

2

You can select both of those elements by their name attribute.

//input[@name='firstName']

and

//input[@name='lastName']

If you are using java (you don't mention your language) and you have a WebDriver defined as "driver" you could use either:

WebElement firstName = driver.findElement(By.xpath("//input[@name='firstName']"));

or alternatively you could look it up specifically by name:

WebElement firstName = driver.findElement(By.name("firstName"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.