Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google login is not working in headless chrome selenium in Jenkins job

Google Login is not working in headless chrome selenium in Jenkins job.

However this is working when I am running on actual chrome.

dvr.get("https://accounts.google.com/signin/v2/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fh%2F141icwbpdm6lq%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin");

dvr.findElement(By.id("identifierId")).click();

dvr.findElement(By.id("identifierId")).clear();

dvr.findElement(By.id("identifierId")).sendKeys("[email protected]");

dvr.findElement(By.xpath("//*[@id=\"identifierNext\"]/span")).click();

dvr.findElement(By.xpath("//*[@id='password']/div[1]/div/div[1]/input")).clear();

dvr.findElement(By.xpath("//*[@id='password']/div[1]/div/div[1]/input")).sendKeys("xyz");

dvr.findElement(By.xpath("//*[@id=\"passwordNext\"]/span/span")).click();

Following error is coming in headless mode.

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"identifierId"} (Session info: headless chrome=76.0.3809.132) (Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.12.6 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: 'Homebells-MacBook-Pro-2.local', ip: 'fe80:0:0:0:ab:bf46:6f97:5e3c%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', >java.version: '1.8.0_144' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, >chrome: {chromedriverVersion: 2.38.552518 (183d19265345f5..., userDataDir: /var/folders/jq/rrf_qymx39s...}, cssSelectorsEnabled: true, databaseEnabled: >false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, >networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, >takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 76.0.3809.132, webStorageEnabled: true} Session ID: 61f1a8512d345d1abf7ca3b40e345602 *** Element info: {Using=id, value=identifierId}

below is the code for launching browser.

if (browser.equalsIgnoreCase("chrome") && OS == "Mac") {

        System.out.println("==============================================" );
        System.out.println("OS Detected : MAC , Browser Launched : Chrome" );
        System.out.println("==============================================" );

        System.setProperty("Webdriver.chrome.driver", "./lib/chromedriver");

        Boolean headlesschrome = true;

        if (headlesschrome==true) {

            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--headless");
            dvr = new ChromeDriver(chromeOptions);
            dvr.manage().window().fullscreen(); 

        }else if (headlesschrome==false)

        {
            dvr = new ChromeDriver();
            dvr.manage().window().fullscreen();
        }

    }
like image 988
HillHacker Avatar asked Oct 31 '25 18:10

HillHacker


1 Answers

Solved google login issue by adding --user-agent flag with headless chrome.

--user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"

Ref: Headless Chrome displays old Google sign-in when signing in with OpenID/OAuth

like image 62
jack44 Avatar answered Nov 02 '25 07:11

jack44



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!