Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I am using WebDriver and I need to use XPath to get the text that appears after the <br></br> which is "59Min" from the below HTML.

<div>

2Hrs, 56Min

<br></br>

59Min

<input value="3hrs"></input>
<input value="4hrs"></input>
</div>

The following code doesn't do it:

var dfs = driver.FindElement(By.XPath("//table[@id='PowerReserveTables2_0']/tbody/tr/td[6]/div/text()[2]")).Text;

Neither if I use following-sibling like this:

/div/br/following-sibling::text()[1]
share|improve this question
    
/div/input/preceding-sibling::[2] Your question is vague but this might lead you in the right direction –  PaulDonny Jun 24 at 23:53
    
Thanks, but that didn't work either. I notice part of my question was chopped off. I am trying to locate the text that appears after the br tags. WebDriver, by nature, always locates elements, but techniques such as "following-sibling::text()" or "div/text()[2]" locate text. They are valid, but don't work in WebDriver. –  MahlerAdmirer Jun 25 at 13:23
1  
In the above code, the "2Hrs, 56Min" and "59Min" are both text within the div tag. In order to be a sibling, the div tag would have to be closed and the second string "59Min" would need to be within another tag. To get the "59Min" simply get the text of the div, and then parse the text to find the characters after the last white space. –  Sam Woods Jun 25 at 15:30

1 Answer 1

Try this:

var dfs = driver.FindElement(By.XPath("//table[@id='PowerReserveTables2_0']/tbody/tr/td[6]/div")).Text.split("<br></br>")[1].trim();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.