Headless Chrome find input field on page

Viewed 572

I initialized driver as shown below:

ChromeOptions chromeOptions = new ChromeOptions();
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
chromeOptions.addArguments("--headless");
driver = new ChromeDriver(chromeOptions);

I get following message, when I execute test.

Starting ChromeDriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 44655 Only local connections are allowed.

org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for presence of element located by: By.xpath:

Given xpath belongs to an input field, which opens a file selector when clicked. It is working perfectly in a normal Firefox. I use WebDriverWait to wait until necessary elements appear.

wait.until(ExpectedConditions.presenceOfElementLocated(mainPage.InputFileField));
1 Answers

When the --headless argument is declared, the driver is thrown to the minimized window 50%, regardless of the " --start-maximized " argument or the " driver.manage()window().maximize(); " command.

If your page has a different DOM in 50% responsive mode, then it does not find the DOM elements of the nonresponsive mode.

If that is the case :

  • Either you adapt your query selector to take into account the repsonsive mode
  • Or you add after the instantiation of your driver:

    this.webDriver.manage (). window (). setSize (new Dimension (1440, 900));

Sorry for my bad English, but I hope this will help more than one ;)

Related