如何使用Selenium Java中的机器人类在无头浏览器中上传文件 [英] How to upload file in headless browser using robot class in selenium java
问题描述
如何在无头浏览器中使用Selenium Java中的机械手类作为sendkeys()方法上载文件,在我的情况下不起作用.我的脚本使用的是Firefox和Selenium Web驱动程序Java
How to upload file in headless browser using robot class in selenium java as sendkeys() method not working in my case. I am using firefox and selenium web driver java for my script
推荐答案
无需使用Robot类即可使用Selenium Java上载文件. 刚开始时,(1)如果是linux,则将文件上传到/tmp文件夹中;如果是Windows OS,则将其上传到temp文件夹中,然后,使用下面的代码上传文件
No need to use Robot class for uploading file using selenium java. Just at first, (1) Upload your files in /tmp folder in case of linux and temp folder in case of windows OS and then, use below code to upload files
String path = FILE_UPLOAD_PATH;
//(Full path with file name from /tmp folder)
driver.findElement(By.id("FILE_INPUT_ID")).sendKeys(path);
它将上传文件.
注意:如果不需要释放内存,请在上传后从/tmp文件夹中删除文件.
Note : Please remove file from /tmp folder after uploading, if no need to free memory.
这篇关于如何使用Selenium Java中的机器人类在无头浏览器中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!