Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Selenium Web driver, finding XPATH expression

Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
author & internet detective
Posts: 40035
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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']
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Those are the largest trousers in the world! Especially when next to this ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic