我编译的 AutoIt 脚本会自动执行操作系统窗口,例如“上传文件选择窗口”。对于谷歌浏览器,它可以工作。但是使用 InternetExplorerDriver 它不会将文件路径发送到操作系统窗口。
下面是代码。我正在运行 testng.xml 来触发浏览器。
import io.github.bonigarcia.wdm.ChromeDriverManager;
import io.github.bonigarcia.wdm.InternetExplorerDriverManager;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import pom.LoginPom;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
* Created by User on 28/5/2017.
*/
public class MyTest1 extends Tests{
private WebDriver driver;
@BeforeTest
@Parameters("Browser")
public void setup(String browser){
if (browser.equals("ie")) {
InternetExplorerDriverManager.getInstance().arch32().setup();
driver = new InternetExplorerDriver();
}
else if (browser.equals("chrome")){
ChromeDriverManager.getInstance().arch32().setup();
driver = new ChromeDriver();
}
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(5,TimeUnit.SECONDS);
driver.navigate().to("http://aspuploader.com/demo/form-singlefile.asp");
}
@Test
public void test1() throws InterruptedException, IOException {
WebElement elem = driver.findElement(By.id("myuploaderButton"));//.click();
JavascriptExecutor ja = (JavascriptExecutor) driver;
ja.executeScript("arguments[0].click();", elem);
Thread.sleep(3000);
Runtime.getRuntime().exec("src/test/java/script.exe");
}
@AfterMethod
public void close(){
driver.close();
}
}
`
AutoIt 脚本:
WinWait("Open", "", 3000)
ControlFocus("Open", "", "Edit1")
ControlSetText("Open", "", "Edit1", "Hello")
ControlClick("Open", "", "Button1")