我编译的AutoIt脚本自动化OS窗口,如"上传文件选择窗口"。对于Google Chrome,它可以使用。但是使用InternetExplorerDriver它不会将文件路径发送到OS窗口。
以下是代码。我正在运行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")
答案 0 :(得分:0)
对于不同的浏览器,tittle和文本有时会将w.r.t更改为autoIT。可能会发生这样的情况:您在Chrome中搜索的tittle不适用于Internet Explorer。我建议重新检查一下网络浏览器的文字和文字。