I'm trying to use headless mode on application having a step with IAP google. It runs without errors when headless mode is off. When the headless mode is On selenium can not locate the element.
I don't know how to fix that. I've tried a lot of configurations for chromedriver but still have the same error.
public class Hooks {
ChromeOptions options = new ChromeOptions();
public static WebDriver driver;
@Before
public void setUp() {
String chromeDriverPath = "C:\\Selenium\\Drivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1080");
//options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
}
Error when try to locate the element:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //button[text() = 'Esqueceu seu e-mail?'] (tried for 5 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
Steps to locate the element:
public BaseClass(WebDriver driver) {
BaseClass.driver = driver;
wait = new WebDriverWait(driver, 5);
}
public void waitVisibility(By elementBy) {
wait.until(ExpectedConditions.visibilityOfElementLocated(elementBy));
}
public void isDisplayed(By elementBy) {
waitVisibility(elementBy);
driver.findElement(elementBy).isDisplayed();
}
public void checkElement() {
isDisplayed(headerLoginGooglePage);
}
The complete error stack trace
Starting ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a) on port 39113
Only local connections are allowed.
dez 12, 2019 4:25:32 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMAÇÕES: Detected dialect: OSS
Dado que o usuário acesse a url do sistema SMAPP Parts and Maintenance # LoginSteps.queOUsuarioAcesseUrlSistemaSMAPP()
Entao exibe tela padrão de login por conta Google # LoginSteps.exibeTelaPadraoLoginContaGoogle()
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //button[text() = 'Esqueceu seu e-mail?'] (tried for 5 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at pageobjects.BaseClass.waitVisibility(BaseClass.java:21)
at pageobjects.BaseClass.isDisplayed(BaseClass.java:51)
at pageobjects.MaintenanceTimeLinePages.visualizarElementoTelaGoogle(MaintenanceTimeLinePages.java:109)
at step_definitions.LoginSteps.exibeTelaPadraoLoginContaGoogle(LoginSteps.java:34)
at ✽.exibe tela padrão de login por conta Google(src/test/resources/features/Login.feature:7)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//button[text() = 'Esqueceu seu e-mail?']"}
(Session info: chrome=78.0.3904.108)
(Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17763 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-AJU29UT', ip: '192.168.12.226', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.43.600210 (68dcf5eebde371..., userDataDir: C:\Users\ZUPPER\AppData\Loc...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:51880}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 78.0.3904.108, webStorageEnabled: true}
Session ID: b148fc1021de85032649ce461e775ab2
*** Element info: {Using=xpath, value=//button[text() = 'Esqueceu seu e-mail?']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
at pageobjects.BaseClass.waitVisibility(BaseClass.java:21)
at pageobjects.BaseClass.isDisplayed(BaseClass.java:51)
at pageobjects.MaintenanceTimeLinePages.visualizarElementoTelaGoogle(MaintenanceTimeLinePages.java:109)
at step_definitions.LoginSteps.exibeTelaPadraoLoginContaGoogle(LoginSteps.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at cucumber.runtime.Utils$1.call(Utils.java:32)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)
at cucumber.runtime.Utils.invoke(Utils.java:26)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:37)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:40)
at cucumber.api.TestStep.executeStep(TestStep.java:102)
at cucumber.api.TestStep.run(TestStep.java:83)
at cucumber.api.TestCase.run(TestCase.java:58)
at cucumber.runner.Runner.runPickle(Runner.java:80)
at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:117)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:55)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:126)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
This error message...
Starting ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a) on port 39113
Only local connections are allowed.
dez 12, 2019 4:25:32 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMAÇÕES: Detected dialect: OSS
Dado que o usuário acesse a url do sistema SMAPP Parts and Maintenance # LoginSteps.queOUsuarioAcesseUrlSistemaSMAPP()
Entao exibe tela padrão de login por conta Google # LoginSteps.exibeTelaPadraoLoginContaGoogle()
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //button[text() = 'Esqueceu seu e-mail?'] (tried for 5 second(s) with 500 milliseconds interval)
.
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//button[text() = 'Esqueceu seu e-mail?']"}
(Session info: chrome=78.0.3904.108)
(Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17763 x86_64) (WARNING: The server did not provide any stacktrace information)
.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-AJU29UT', ip: '192.168.12.226', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.chrome.ChromeDriver
...implies that the ChromeDriver was unable to communicate with Browsing Context i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Supports Chrome v69-71
Supports Chrome version 78
So there is a clear mismatch between Selenium Client v3.141.59 , ChromeDriver v2.43 and the Chrome Browser v78.0
Ensure that:
@Test
as non-root user.driver.quit()
within tearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.