Selenium Web驱动程序取消Firefox下载 [英] Selenium Web Driver Cancelling Firefox Downloads

查看:88
本文介绍了Selenium Web驱动程序取消Firefox下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图取消Firefox中带有硒的弹出式下载窗口.我可以切换窗口并关闭警报窗口,但似乎无法选择下载窗口.有什么想法吗?

I'm trying to cancel the pop up download windows in Firefox with selenium. I can switch windows and close alert windows, but I can't seem to select the download window. Any ideas?

环顾四周,似乎Selenium RC无法处理下载窗口,因为它们取决于操作系统.但是,对于Selenium Web Driver,此问题是否相同?我知道可以使用autoit来解决此问题,但是如果可能的话,我希望将其全部保留在Java硒中.谢谢.

Looking around, it seems Selenium RC can't do handle the download window because they depend on the OS. However, is this problem the same for the Selenium Web Driver? I know a solution to this can be done with autoit, but I'd like to keep it all in Java selenium if possible. Thanks.

推荐答案

WebDriver无法直接与对话框窗口进行交互,这是因为对话框窗口是操作系统的域,而不是网页的域.但是可以使用以下方法在对话框窗口上执行操作 名称空间System.Windows.Forms的SendKeys类方法SendWait()

WebDriver cannot directly interact with dialog windows this is because dialog windows are the domain of the operating system and not the webpage. However its possible to do actions on dialog windows using SendKeys class method SendWait() of name space System.Windows.Forms

using System.Windows.Forms;

在示例代码中,按下了PLUpload按钮,这将打开Windows对话框以选择要上传的文件.

In the example code below a PLUpload button is pressed, which opens a Windows Dialog to select the file to upload.

编写以下行将键值发送到显示的对话框窗口.

Following lines are written to send key values to the dialog window displayed.

SendKeys.SendWait(@"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
SendKeys.SendWait(@"{Enter}");

可以在 http://msdn.microsoft.com/zh-cn/library/system.windows.forms.sendkeys.aspx

using System;
using System.Windows.Forms;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Interactions;
using NUnit.Framework;
namespace BusinessCreation
{
    class PlUpload
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.plupload.com/example_queuewidget.php");
        driver.FindElement(By.XPath("//object[@data='/plupload/js/plupload.flash.swf']")).Click();
           SendKeys.SendWait(@"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
           SendKeys.SendWait(@"{Enter}");
        }
     }
}

这篇关于Selenium Web驱动程序取消Firefox下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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