I need to assert if page body contains text "error", how would I do that? I got to this point and I am getting error on .getText
driver.FindElement(By.TagName("body")).getText().Equals("Error")
I need to assert if page body contains text "error", how would I do that? I got to this point and I am getting error on .getText
driver.FindElement(By.TagName("body")).getText().Equals("Error")
You don't really want to do it this way... but since you asked, here is the answer.
driver.FindElement(By.TagName("body")).Text.Contains("Error");
You were using .getText()
which is Java. You were also using .Equals()
but what you meant was .Contains()
because the entirety of the body tag is likely not to be only "Error".
What I would recommend is for you to narrow down to the element that actually contains the "Error" text and then use the line above (with the proper locator), e.g.
driver.FindElement(By.Id("the ID of the element that contains Error")).Text.Contains("Error");
You'd have to provide the surrounding HTML for the element for us to help you any more specifically.