In WebDriver I need to locate a text that's sibling to a tag



  • 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]



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



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2