Java 如何使用SeleniumWebDriver附加文件?

Java 如何使用SeleniumWebDriver附加文件?,java,selenium,Java,Selenium,我想使用SeleniumWebDriver添加附件。我的输入标签如下所示 输入标签 输出:0B已上载 此方法可能有什么错误?我请求您使用AutoIt脚本: 用于上载文件WinWaitActiveFile的窗口的标题 上传 要上载的文件sendc:\samplefile.txt Send{ENTER} 将此文件另存为AddFile.au3 然后使用以下代码调用exe文件 通过编译上述AutoIt脚本创建 try { String[] commands = n

我想使用SeleniumWebDriver添加附件。我的输入标签如下所示

输入标签

输出:0B已上载


此方法可能有什么错误?

我请求您使用AutoIt脚本:

用于上载文件WinWaitActiveFile的窗口的标题 上传

要上载的文件sendc:\samplefile.txt Send{ENTER}

将此文件另存为AddFile.au3

然后使用以下代码调用exe文件

通过编译上述AutoIt脚本创建

try {                    
String[] commands = new String[]{};             
commands = new String[]{"C:\\Program Files (x86)\\AutoIt3\\Examples\\Addfile.exe"}; //location of the autoit executable   
Runtime.getRuntime().exec(commands);    
} 
catch (IOException e) 
{
}

WebElement addFileElement = driver.findElement(By.className("add-file")); // you can find the element to upload the file in different way,  class name used  here, you can use xpath

 addFileElement.click();
这是auto-it.au3文件。 您需要安装auto-it并创建任何文件,比如upload.au3 右键单击此文件并编译它以创建upload.exe 现在,在webdriver代码中,编写以下代码

---->>>
        driver.findElement(By.xpath("//input[@name='_attFile_']")).click();
        Thread.sleep(5000);
        Runtime.getRuntime().exec("F:\\AutoIt\\upload.exe");
---->>>
可能重复的
try {                    
String[] commands = new String[]{};             
commands = new String[]{"C:\\Program Files (x86)\\AutoIt3\\Examples\\Addfile.exe"}; //location of the autoit executable   
Runtime.getRuntime().exec(commands);    
} 
catch (IOException e) 
{
}

WebElement addFileElement = driver.findElement(By.className("add-file")); // you can find the element to upload the file in different way,  class name used  here, you can use xpath

 addFileElement.click();
IF WinExists("File Upload") Then
   WinWaitActive("File Upload")
   ControlSetText("File Upload","",1148,"C:\src.zip")
   ControlClick("File Upload","",1)


Else
   MsgBox(1,"ERROR","UNABLE TO VIEW THE FOLDER")
EndIf
---->>>
        driver.findElement(By.xpath("//input[@name='_attFile_']")).click();
        Thread.sleep(5000);
        Runtime.getRuntime().exec("F:\\AutoIt\\upload.exe");
---->>>