我编写了自动IT代码,用于通过自动化在给定位置保存pdf。代码如下
$sSaveAsWindow = "Enter name of file to save to…"
WinWait($sSaveAsWindow,"")
If Not WinActive($sSaveAsWindow,"") Then WinActivate($sSaveAsWindow,"")
WinWaitActive($sSaveAsWindow,"")
ControlCommand ($sSaveAsWindow, "", "ToolbarWindow322", "SendCommandID", 41063)
ControlSetText($sSaveAsWindow, "", "Edit1", "D:\document")
ControlClick($sSaveAsWindow, "", "Button1")
此代码在Firefox中保存文件,代码如下。在这里我首先按下鼠标右键,然后按下保存文件的快捷键,即" CTRL + k"它在给定位置保存文件。
Actions save_pdf = new Actions(driver);
Action save_action = save_pdf.contextClick(driver.findElement(By.xpath("/html/body/div/div[5]/div/div[6]/ul/li[2]/a"))).sendKeys(Keys.chord(Keys.CONTROL, "k")).build();
save_action.perform();
Thread.sleep(4000);
String [] cmds = new String [1];
cmds[0]= "D:\\Demo\\TestCases\\lib\\save_pdf.exe";
Process pp1 = Runtime.getRuntime().exec(cmds);
Thread.sleep(4000);
pp1.destroy();
但这件事在Chrome和IE中无效。
是否还有其他快捷方式可以按"保存"在IE和Chrome中。
提前致谢