File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Selenium Web driver, finding XPATH expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Selenium Web driver, finding XPATH expression" Watch "Selenium Web driver, finding XPATH expression" New topic

Selenium Web driver, finding XPATH expression

sugan san
Ranch Hand

Joined: May 23, 2013
Posts: 47
Hi I need to write XPATH expression for finding input projectName from the below XML and have to enter/sendkeys with that using selenium webdriver. Anyone can help me building xpath expression?

<div class="container-fluid container-fluid-my">
<div class="row-fluid">
<div class="row-fluid" style="margin-bottom: -22px; margin-top: 5px;">
<div class="row-fluid">
<div class="span12">
<div class="info-container">
<li class="labelArrow">Project Name</li>
<li class="pointer"/>
<input id="projectName" class="projectmetadata" type="text" placeholder="Add Project Name" name="projectName" value=""/>

I already tried many options like

But its not working.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

This means find input tags with an id of project name (so far so good) and then look for child input tags with type text. This isn't what you want because an input tag can't have another one as nested element.

Is there any reason you can't just do //input[@id='projectName']? Ids in HTML are supposed to be unique.

If the HTML is poorly formed and has duplicates, try //input[@id='projectName'][@type='text']

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Doug Slavens

Joined: Sep 10, 2013
Posts: 11
Have you tried creating an html file from the xml, opening it in firefox, and recording the input using the Selenium IDE plugin? Once it is recorded, copy and paste the input line from the IDE as Java into your code. I do agree, this line:


or the one mentioned earlier should work.
Roland Schmit

Joined: Oct 17, 2013
Posts: 8

the Firefox Add on Firebug is a great tool to get xpath or css expressions.

I agree. Here's the link:
subject: Selenium Web driver, finding XPATH expression
It's not a secret anymore!