Object iframe is not present on Headless Chrome, please help

Hi, I have created my automation test as below:
//Katalon version = 7.0.0
//Selenium version = 3.141.59
//Chrome version = 78.0.3904


TestObject tObjClock = new TestObject()
tObjClock.addProperty(“xpath”, ConditionType.EQUALS, “.//*[@id=“world-clock-controller”]”)
WebUI.verifyElementPresent(tObjClock, 30)

TestObject tObjLogo = new TestObject()
tObjLogo.addProperty(“xpath”, ConditionType.EQUALS, “.//*[@id=“logo”]”)
WebUI.verifyElementPresent(tObjLogo, 30)

TestObject tObjIFrame = new TestObject()
tObjIFrame.addProperty(“xpath”, ConditionType.EQUALS, “.//iframe[@id=“left-main-menu-view”]”)
WebUI.verifyElementPresent(tObjIFrame, 30)

The test above had passed all when running on Chrome, Firefox, IE, Firefox(headless), but NOT passed when running Chrome(headless) due to error “Unable to find the element located by ‘By.xpath: .//iframe[@id=“left-main-menu-view”]’. Please recheck the objects properties to make sure the desired element is located.”

Please help me how to resolve it.

@SonTT6

The browser may behave differently between headless mode and GUI mode. One direction to explore is to use getPageSource() to get the sources between these modes and compare them.

Do you really need to run the test in headless mode ? The performance gain is not that significant, nevertheless, you’d often have to write the test cases in a different way when running headless.

@ThanhTo: Thank you for your quick reply, I’ve just tried driver.getPageSource() and found that <iframe ng-style=“view.style” id=“left-main-menu-view”…> was generated on Chrome but WAS NOT on Chrome(headless).
So do you think this issue is leaded by chromedriver mode? Could you please help me to resolve it? I really need to run the test in headless (chrome) mode.

I think your best bet is to create a new test case that gets executed exclusively in headless mode. You’d have to re-base your test on the page source which appears during headless execution. You’d need to first see if the object you want to find is available in the page source, and then base your locator accordingly.