I am using Selenium to verify that a new user role has been successfully created, but, when I run Selenium (Java) in headless mode I am getting randomly getting empty strings returned in getText()
public List<String> getRoles() {
String allRolesXpath = String.format("%s%s", TABLE_XPATH, ROLES_XPATH);
List<WebElement> tableElements = webDriver.getWebDriver().findElements(By.xpath(allRolesXpath));
List<String> roles = new ArrayList<>();
for (WebElement element : tableElements) {
String role = WebCtrlFactory.getInstance()
.getByElement(TextCtrl.class, element).getText();
roles.add(role);
}
return roles;
}
I am using the Chrome web driver as the website only supports Chrome based browsers. I am not sure if there are many others I can move to as as it checks for Chro(e)|(ium) based browsers.
I have read numerous other posts about people seeing this issue (this, this), but I haven't found a workable solution. Any suggestions or help would be very welcome.