Search code examples
htmlseleniumxpathfirebug

Getting xpath of span text


I have a HTML page with an element,

<div class="selectedCategory" style="" title=""> <div class="selectedCategoryName" style="" title="">Base programming</div>

The xpath I was trying to use is,

//*[contains(div,'Base programming') and @class='selectedCategoryName'] - I'm getting no so such element when I try using firebug.

If I use individual xpaths like, //*[contains(div,'Base programming') and //*[@class='selectedCategoryName'] - It works

But it tends to return so many element on the page. I need a xpath combining the above 2 elements. Please help me out here!


Solution

  • These xpaths may help you to find the element with Title "Base programming":

    "//div[@class='selectedCategory']/div[text()='Base programming']"

    OR

    "//div[@class='selectedCategory']/div[@class='selectedCategoryName']"

    Let me know if this helps you.