如何使用C#通过Selenium-RC处理对话框 [英] How to handle dialog box through Selenium-RC using C#

查看:85
本文介绍了如何使用C#通过Selenium-RC处理对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我现在正在使用 selenium RC和C#。我想从应用程序下载文件。当我点击一个按钮时,会出现一个弹出对话框,告诉打开,保存和取消。我无法通过 selenium RC(C#)来处理这种类型的弹出窗口。



任何人都可以帮助我解决这个问题它会尽快。



提前致谢,

Dinesh

Hi,
I am now using the selenium RC with C#. I want to download a file from application. when I am clicking on a button one pop-up dialog box is coming which tells open,save and cancel. I am not able to handle this type of pop-up through selenium RC(C#).

Can anyone help me on this to resolve it as soon as possible.

Thanks in advance,
Dinesh

推荐答案

我使用selenium遇到了同样的问题,我假设当弹出那个盒子时你总是希望下载它正确吗?



我最终通过firefox运行我的selenium并创建了一个自定义的firefox配置文件以运行它。在这样做时,我能够说任何文件类型的CSV自动将其保存到c:\ temp目录。



这是我的MimeTypes.rdf和首选项。 js for firefox。使用selenium你可以使用自定义的firefox配置文件来运行selenium,这是一个很好的文档和互联网上你应该能够轻松找到的大量例子。快速搜索发现此链接例如: http://garbuz.com/ 2010/07/31 / running-selenium-with-custom-firefox-profile / [ ^ ]



mimeTypes.rdf(定义你想要自动的文件)下载)

I ran into same issue using selenium, im making the assumption that when that box pops up you always wish to download it correct?

I ended up running my selenium through firefox and created a custom firefox profile in order to run it. In doing so i was able to say any file type of CSV automatically save it to c:\temp directory.

Here is my below MimeTypes.rdf and preferences.js for firefox. Using selenium you have the ability to run selenium using a custom firefox profile, this is well documented and plenty of examples on the internet that you should be able to easily find. A quick search found this link for example: http://garbuz.com/2010/07/31/running-selenium-with-custom-firefox-profile/[^]

mimeTypes.rdf (defines what files you want to auto download)
<rdf:rdf xmlns:nc="http://home.netscape.com/NC-rdf#" xmlns:rdf="#unknown">
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:description rdf:about="urn:root">
                   NC:en-US_defaultHandlersVersion="3" />
  <rdf:description rdf:about="urn:mimetype:application/vnd.ms-excel">
                   NC:value="application/vnd.ms-excel"
                   NC:editable="true"
                   NC:description="CSV document"
                   NC:alwaysAsk="false"
                   NC:saveToDisk="true">
    <nc:fileextensions>csv</nc:fileextensions>
    <nc:fileextensions>xls</nc:fileextensions>
    <nc:fileextensions>xlb</nc:fileextensions>
    <nc:fileextensions>xlt</nc:fileextensions>
    <nc:handlerprop rdf:resource="urn:mimetype:handler:application/vnd.ms-excel" />
  </rdf:description>
  <rdf:description rdf:about="urn:mimetype:handler:text/csv">
                   NC:saveToDisk="true"
                   NC:alwaysAsk="false" />
  <rdf:description rdf:about="urn:mimetype:text/csv">
                   NC:fileExtensions="csv"
                   NC:description="CSV document"
                   NC:value="text/csv"
                   NC:editable="true"
                   NC:alwaysAsk="false"
                   NC:saveToDisk="true">
      <nc:handlerprop rdf:resource="urn:mimetype:handler:text/csv" />
  </rdf:description>
</rdf:description></rdf:description></rdf:rdf>







preferences.js(您基本上可以在firefox中获取当前的配置文件并将这两行添加到其中)




preferences.js (you can basically take your current profile in firefox and add these two lines to it)

user_pref("browser.download.dir", "C:\\temp");
user_pref("browser.download.folderList", 2);


您好,谢谢 David Wimbley
我使用 IE 作为我的浏览器。所以,我无法将你的解决方案映射到我的问题。



我修复了这个问题。我所做的只是使用 ASCII键码值和 WaitFor 条件在Selenium中提供的帮助。



i ,e,

Hi Thanks David Wimbley,
I am using IE as my browser. So, i couldn''t map your solution to my problem.

And i fixed the issue. All i did is go for using the help of ASCII Keycode values and WaitFor condition available in Selenium.

i,e,
// Button - To Trigger File Download Button
selenium.click(Button);
selenium.waitForPageToLoad("10000");
selenium.AltKeyDown();
selenium.AltKeyUp();
Thread.Sleep(3000);
selenium.KeyPressNative("27"); ///27-ESC
Thread.Sleep(3000);





这就是我的方式,发现工作正常。



您好 Ramasai ,试试这个解决方案。一切顺利。



This is the way i did, and found working fine.

Hi Ramasai, try this solution. all the best.


您好,谢谢David Wimbley,



我使用的是IE浏览器。所以,我无法将你的解决方案映射到我的问题。



我修复了这个问题。我所做的只是使用在Selenium中提供的ASCII Keycode值和WaitFor条件的帮助。



i,e,



Hi Thanks David Wimbley,

I am using IE as my browser. So, i couldn''t map your solution to my problem.

And i fixed the issue. All i did is go for using the help of ASCII Keycode values and WaitFor condition available in Selenium.

i,e,

// Button - To Trigger File Download Button
selenium.click(Button);
selenium.waitForPageToLoad("10000");
selenium.AltKeyDown();
selenium.AltKeyUp();
Thread.Sleep(3000);
selenium.KeyPressNative("27"); ///27-ESC
Thread.Sleep(3000);









这就是我的方式,并且发现工作正常。



您好 Ramasai ,试试这个解决方案。一切顺利。





This is the way i did, and found working fine.

Hi Ramasai, try this solution. all the best.


这篇关于如何使用C#通过Selenium-RC处理对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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