Hello,
I’m trying to run file upload in headless mode, I have tried different ways, but not work. How can I get file upload in headless mode?
- The import button in DOM is like below:
It is not input tag, I’m not sure if this will impact on the result ? - I need it to run in headless mode.
Following are all the ways I have tried:
-
Using WebUI.uploadFile keyword
Not work in default mode and headless mode. -
Define custom Keywords like below:
public class MyTools {
@Keyword
def uploadFile (TestObject to, String filePath) {
WebUI.click(to)
WebUI.delay(2)
StringSelection ss = new StringSelection(filePath);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.delay(1000) robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.delay(1000) //NOTE THE DELAY (500, 1000, 1500 MIGHT WORK FOR YOU) robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER);
}
}
This way can run in default Chrome mode, but will always fail in headless mode. -
Use following code:
WebDriver driver = DriverFactory.getWebDriver()
String path = ‘D:\Daily task\New PW User.csv’
driver.findElement(By.xpath("//*[@id=‘app’]/div/section/div/section[1]/div[1]/div/button")).sendKeys(path);
Not work both in default mode and headless mode.
Can someone help me on this?