I am trying to find the xpath of the element below, so that I can later get the text using Ruby Selenium-webdriver (ie. helloPage.mainHeader.get_text).
<div class="container">
<div class="template-section">
<div class="front">
<h3 class="containerHeading">
<i class="icon_image"></i>
"Hello world <-----------------------3 whitespaces
"
</h3>
</div>
</div>
</div>
I've worked on xpaths but everytime I rerun the test it timesout essentially the element does not exist. It is clearly visible on the UI and not hidden.
Why is my xpath is wrong? I have tried the following:
//div[@class='container']//div[@class='template-section']//div[@class='front']//h3[@class='containerHeading']//div[@class='front']//h3[@class='containerHeading']//h3[@class='containerHeading']
I did put sleep prior to executing helloPage.mainHeader.get_text, where mainHeader has the XPath expression, and that didn't work. Is there something mysterious about the Hello World text? The format is indeed like the way I typed it out.
xpathsyou have provided they are all valid. However, for 'A' you could rewrite it as//div[@class='container']/div[@class='template-section']/div[@class='front']/h3[@class='containerHeading'], note the single fore-slashes separating the elements. So are you seeing an error or exception when you try to find the element? Have you used another tool to check that yourxpathis valid as well?