这将打开文件附件对话框着点击按钮 [英] cant click button which opens file attachment dialog

查看:142
本文介绍了这将打开文件附件对话框着点击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在usinng 硒2测试版即可。我试图点击按钮,打开文件附件对话框。但是当我点击它没有任何反应。

i'm usinng selenium 2 beta. i'm trying to click button which opens file attachment dialog. but when i click it nothing happens.

<input class="zf" name="Passport" id="PassportUpload" type="file" onclick="return { oRequired : {} }" maxlength="524288"> 


driver.findElement(By.name("Passport")).click();

只用硒硒不是2

我可以点击它很容易。

using just selenium not selenium 2 i can click it easily.

推荐答案

我想,这个问题使用Internet Explorer时,因为IE和FF处理文件输入稍有不同的只是:在FF您可以点击按钮或领域调用打开对话框,而在IE浏览器,你可以点击在球场上的按钮或双击

I guess that the issue is only when using Internet Explorer since IE and FF handles the File Input slightly different: in FF you can click on the button or the field to invoke the Open dialog, while in IE you can click on the button or double-click on the field.

本机的webdriver事件,所以它发送一个本地鼠标点击它转换为输入字段点击文件输入控制。

WebDriver using native events so it is sending a native mouse click to the File Input control which is translated to the click on the input field.

它在硒的工作1,因为它使用JavaScript来触发事件。为了使其在工作的webdriver你需要调用JavaScript的:

It was working in Selenium 1 because it is using the JavaScript to fire the events. To make it work in WebDriver you need to invoke the JavaScript:

WebElement upload = driver.findElement(By.name("Passport"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", upload);

然而,code abouve不会在Firefox中,这样你就可以使用这样的:

However the code abouve will not in Firefox, so you can use something like:

WebElement upload = driver.findElement(By.name("Passport"));
if (driver instanceof InternetExplorerDriver) {
    ((JavascriptExecutor)driver).executeScript("arguments[0].click();", upload);
} else {
    upload.click();
}

这篇关于这将打开文件附件对话框着点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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