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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • 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">
<ul>
<li class="labelArrow">Project Name</li>
<li class="pointer"/>
<li>
<input id="projectName" class="projectmetadata" type="text" placeholder="Add Project Name" name="projectName" value=""/>
</li>
</ul>
</div>

I already tried many options like
driver.findElement(By.xpath("//input[@id='projectName']//input[@type='text']")).sendKeys("test");

But its not working.
 
author & internet detective
Posts: 40035
809
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.
//input[@id='projectName']//input[@type='text']

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']
 
Greenhorn
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:

driver.findElement(By.xpath("//input[@id='projectName']")).sendKeys("test");

or the one mentioned earlier should work.
 
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Roland
 
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic