Search code examples
c#seleniumselenium-webdriverselenium-chromedriverbrowser-automation

Cant find Text Element in Headless Mode Selenium C#


I am simply trying to get certain text in headless mode that I can get in windowed mode. In headless mode the string is just "" (Empty).

In windowed mode it works perfectly fine using the code below:

string actualStatusText = p_Util.Driver.FindElement(By.XPath("html/body/div[3]/div/table/tbody/tr[1]/td[4]")).Text;
//body > div.container.body-content > div > table > tbody > tr:nth-child(1) > td:nth-child(4)
//html/body/div[3]/div/table/tbody/tr[1]/td[4]

The comments show the two different ways I can get the text in windowed mode tested in Headless but doesn't work. (Tried both CSS and XPath)


Solution

  • Using .getAttribute("innerText") fixed the issue!

    Thanks to @RyanWilson in the comments.