硒executeScript挂在IE上 [英] selenium executeScript hangs on IE

查看:103
本文介绍了硒executeScript挂在IE上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我已经在网上搜索了2天,以解决模式对话框问题.很棒的信息在那里,除了IE之外,其他所有功能都适用.我正在尝试打开文件上传对话框并选择一个新文件.我创建了autoIT脚本,它们与FF和Chrome一起正常工作.当我尝试使用IE时,"executeScript"不会返回我的测试脚本.在IE中,文件上传"对话框打开.但这就是我的脚本停止的地方.如果我手动运行autoIT脚本,则在文件上传"对话框关闭后,它将返回测试脚本.

OK folks, I've searched the web for 2 days to solve the modal dialog problem. Great information out there and it all works except for IE. I'm trying to open a file upload dialog and select a new file. I created autoIT scripts and they work just fine with FF and Chrome. When I try with IE the "executeScript" does not return back to my test scripts. In IE the "file upload" dialog is opened. But That is where my scripts stops. If I manually run the autoIT script, it returns back to the test script after the "file upload" dialog closes.

//WebDriver driver = new FirefoxDriver();
// processPage(driver);
WebDriver ieDriver =new InternetExplorerDriver();
processPage(ieDriver);
// WebDriver chromeDriver = new ChromeDriver();
// processPage(chromeDriver);

. . .其他代码 .

. . . other code . .

WebElement element = driver.findElement(By.name(uploadDifferntFile));
if (driver instanceof InternetExplorerDriver) {
  ((InternetExplorerDriver) driver).executeScript("arguments[0].click();", element);

} else if(driver instanceof FirefoxDriver){
  ((FirefoxDriver) driver).executeScript("arguments[0].click();", element);

} else if(driver instanceof ChromeDriver){
  ((ChromeDriver) driver).executeScript("arguments[0].click();", element);

}

. . .自动IT . .

. . . autoIT . . .

try {
    Process proc = Runtime.getRuntime().exec(fileToExecute);
} catch (IOException e) {
    System.out.println("Failed to execute autoIT");
    e.printStackTrace();
}

感谢您的支持

推荐答案

我刚刚遇到了同样的问题,因为sendKeys对于使用Internet Explorer的人来说并不是一个稳定的解决方案.因此,我使用AutoIt构建了一个变体.

I've just stepped in the same problem, because sendKeys wasn't a stable solution for me working with Internet Explorer. So I build a variation with AutoIt.

对于Firefox,我使用JavaScript;对于IE,我双击输入字段:

For Firefox I use the JavaScript and for IE I do a doubleclick on the input field:

// fileInput is the WebElement resulting from the input field with type file
if (browser == "FF") {
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", fileInput);
} else {
    Actions action = new Actions(driver);
    Action doubleClick = action.doubleClick(fileInput).build();
    doubleClick.perform();
}   

这篇关于硒executeScript挂在IE上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆