MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

SendKeys doesn't work properly in headless mode #180

Closed Ulyana-Yeryksonava closed 7 years ago

Ulyana-Yeryksonava commented 7 years ago

I got the page with the simple html-code (see it here: pageCode.txt ) and am trying to upload an image and then find it's name in page source code using javascript. When I do such manipulations in non-headless mode, everything OK, but in headless mode there is an unexpected result. Code is here:

Non-headless mode:

JBrowserDriver driver = new JBrowserDriver(Settings.builder().headless(false).buildCapabilities());
driver.get("http://localhost:8080/html/pageother.html");
driver.findElement(By.id("uploadFile")).sendKeys("D:\\1.jpeg");
System.out.println(((JavascriptExecutor) driver).executeScript("return document.getElementById('uploadFile').files[0].name;"));

Result in console : 1.jpeg

Headless-mode:

JBrowserDriver driver = new JBrowserDriver(Settings.builder().headless(true).buildCapabilities());
driver.get("http://localhost:8080/html/pageother.html");
driver.findElement(By.id("uploadFile")).sendKeys("D:\\1.jpeg");
System.out.println(((JavascriptExecutor) driver).executeScript("return document.getElementById('uploadFile').files[0].name;"));

Result in console: D