selenium - How to get the text only from the child element - Webdriver - Java -
i trying text child element. see below:
<strong class="envmain"> <strong id="currentclock">11:19</strong> gmt </strong>
i gmt text.
i tried writing xpath like: .//*[@id='userenvironmentinfo']/div[2]/a/strong/text()]
way element not found.
thanks in advance.
update of html:
<div class="datetime"> <a class="envpicker" title="change timezone" href="javascript:void(0);"> <span class="envdd">▾</span> <span class="envicon datetimeicon">the time is:</span> <strong class="envmain"> <strong id="currentclock">17:34</strong> gmt </strong> <span id="currentday" class="envmore">monday</span> <span id="currentdate" class="envmore">14.04.2014</span> </a> <div class="envcontainer"> <ol id="timezoneoptions" class="envlist"> <li class="envitem"> <a class="envoption" title="set timezone gmt-12" onclick="return false;" rel="-12" href="javascript:void(0);"> <strong class="envmain">gmt-12</strong> <span class="envmore">current time:01:25</span> </a> </li> <li class="envitem"> <a class="envoption" title="set timezone gmt-11" onclick="return false;" rel="-11" href="javascript:void(0);">
and here elements continue until gmt +12.
the xpath you're searching is:
//strong[@class='envmain']/text()
this xpath returns text, not web element.
if want text using selenium + java can try following:
driver.findelement(by.xpath("//strong[@class='envmain']")).gettext();
seems gettext function not return gmt
. can parse string after getting text:
string s = driver.findelement(by.xpath("//strong[@class='envmain']/strong[id='currentclock']/..")).gettext(); s = s.substring(s.lastindexof(' ') + 1);
Comments
Post a Comment