I am using selenium script to test login flow. After entering username, I need to click next button and it should redirect me to Identity provider page. If I don't run my selenium script in headless mode, it works fine, but same things fails when I run in headless mode. Here are the args that I am setting for chromeDriver
ChromeOptions options = new ChromeOptions(); options.addArguments("--headless=new"); // Run in headless mode options.addArguments("--disable-gpu"); // Applicable to Windows machines options.addArguments("--no-sandbox"); // Bypass OS security model options.addArguments("--window-size=1920,1080"); // Set window size options.addArguments("--disable-application-cache"); options.addArguments("--ignore-certificate-errors"); options.addArguments("--start-maximized"); options.addArguments("--enable-javascript"); driver = new ChromeDriver(options);
Below is the code for button what I am trying to find and click
WebElement nextButton = driver.findElement(By.xpath("//*[@id='next-btn' or @title='Next']")); (JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", nextButton); ((JavascriptExecutor) driver).executeScript("arguments[0].click();", nextButton) // Dispatch the 'input' event to simulate user interaction ((JavascriptExecutor) driver).executeScript("var event = new Event('input', { bubbles: true }); arguments[0].dispatchEvent(event);", nextButton); System.out.println("Button clicked"); wait.until(ExpectedConditions.urlContains("https://myidppage.com"));
Looks like click() is working as its printing 'Button clicked' but the next line where I am expecting a certain webpage to load isn't working. I debugged and ffound out it remains on same page. While same is working in non-headless mode.
Please help me understand whats going wong