使用Autoit在使用硒时处理文件上传窗口。按照以下步骤。
1)下载Autoit并安装。
2)然后将下面的代码写在记事本中。将以下代码中的文件路径更改为您尝试从selenium脚本上传的文件路径。将其另存为uploadhandler.au3
。请注意,扩展名应该是au3。
WinActivate("Choose file");
Local $file = "c:\yourpath\howtoupload.doc"
ControlSetText("Choose file", "", "Edit1", $file)
ControlClick("Choose file", "", "Button2")
3)右键单击该保存的脚本文件并从上下文菜单中单击“编译脚本”。这将生成uploadhandler.exe
文件。
4)将这个uploadhandler.exe文件放在你的本地驱动器中,并在你需要使用下面的代码上传文件的任何地方在你的selenium-java代码中运行这个exe文件。
Process proc = Runtime.getRuntime().exec("C:\\path for your exe file\\uploadhandler.exe");
例如: -
driver.findelement(byid("browse")).click();
Process proc = Runtime.getRuntime().exec("C:\\path for your exe file\\uploadhandler.exe");
//rest of your selenium code continues here.
我试图UR code.WebElement点击=(driver.findElement(By.id( “bckBlack”))); \t click.click(); \t尝试{ \t \t \t过程proc等于调用Runtime.getRuntime()EXEC(“C:\\用户\\ f.gandhi.mohanam \\ seleniumworkspace \\ uploaderhandler。exe文件“); \t \t}赶上(IOException的发送){ \t \t \t // TODO自动生成的catch程序块 \t \t \t e.printStackTrace(); \t \t} \t \t driver.manage()超时().implicitlyWait(10L,TimeUnit.SECONDS); \t \t driver.findElement(By.xpath(“// * [@ id ='save']”))。click(); – Feroze 2013-03-27 05:53:13