Search code examples
c#seleniumassert

Selenium: What causes an FindElement to bring back nothing?


I just was curious what would cause a FindElement method to bring back nothing (not null) even though the element is there on the page and in the HTML. Every once in awhile, when I have an Assert.AreEqual method in my code, it'll have this issue.

My Asserts usually look like the following:

Assert.AreEqual(stringValue, FindElement(By.XPath("<XPath path>")).Text);

And the error message comes back saying that the FindElement came back as "<>", like there was no value. Is it possible the my script is going too fast and skips over it or is there some other underlining issue.


Solution

  • This could happen when this text on your webpage is not actually stored as an innerHTML, it could be in value property of your element and when using Text method you get only innerHTML so it looks like it's empty. Try with GetAttribute, inspect your element to find how it stores this text.

    Hope I understood your problem correctly. :D