Skip to content Skip to sidebar Skip to footer

Selenium Webdriver Find String From A Comment (c#)

I have in a website a line like this: How can I take that '100.000' and put it in a string? I tried something like this i

Solution 1:

No, you cannot directly target comments with FindElement() - it will only work for actual elements - not the text or comment nodes.

You need another way. The idea is to first either get the complete source of the page using driver.PageSource or to get the inner or outer HTML of an element that contains the comment node using elm.GetAttribute("innerHTML") or elm.GetAttribute("outerHTML") where elm could defined in your case as the row containing the comment node inside:

IWebElementelm= driver.FindElement(By.XPath("/html/body/div[2]/div[2]/table[1]/tbody/tr[2]"));

Then, you have several options for how to extract the comment from an HTML string. The best, I think, is to use an HTML parser, like HTML Agility Pack:

Post a Comment for "Selenium Webdriver Find String From A Comment (c#)"