硒的webdriver测试一个ActiveX控件 [英] Selenium WebDriver to test an ActiveX Control

查看:2126
本文介绍了硒的webdriver测试一个ActiveX控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直为我的公司使用Selenium的IWebDriver网站上的一些测试的自动化,并已运行到某些ActiveX控件(一个对话框来选择和上传文件),我似乎无法实现自动化。我一直没能在互联网上找到关于这个的任何具体信息。

I have been working to automate some tests for my companies website using Selenium's IWebDriver, and have run into some ActiveX controls (a dialog to select and upload a file) that I cannot seem to automate. I haven't been able to find any specific information on this on the internet.

我,但是,可以通过在页面内引发了开放式要素实际加载对话框(用户必须手动单击该文件目的地和开门按钮),但它未能通过测试(此code没有意义的我,为什么它打开的对话​​框中,我本来送键并单击以相反的顺序)。

I am, however, able to actually load the dialog box by triggering the "open" element within the page (the user will have to manually click the file destination and the open button), but it fails the test (this code doesn't make sense to me as to why it opens the dialog box, I originally had the SendKeys and Click in reverse order).

private void UploadFile()
    {
        foreach (var element in driver.FindElements(By.TagName("button")))
        {
            string open = element.Text;
            if (open == "Open")
            {
                element.SendKeys(@"My\Relative\Path");
                element.Click();
            }
        }
    }

我试着我的code范围内执行JavaScript来打开该文件,但我尝试每一次失败,我的同事告诉我,因为ActiveX控件文件上传它不会反正工作。

I've tried to execute JavaScript within my code to open the file, but my attempts have failed each time and my coworkers have told me that it wouldn't work anyways since ActiveX controls the file upload.

有什么想法?

谢谢!

推荐答案

AutoIt的是这个解决方案。我能到我的C#项目中执行脚本。

AutoIt was the solution for this. I was able to execute a script within my C# project.

private void UploadFile()
    {
        foreach (var element in driver.FindElements(By.TagName("button")))
        {
            string open = element.Text;
            if (open == "Open")
            {

                element.SendKeys(@"C:\My\Relative\Path\");
                element.Click();

                string executable = @"C:\My\Relative\Path\fileUploadScript2.exe";
                System.Diagnostics.Process.Start(executable);
            }
        }
    }

由于@SiKing在正确的方向推。

Thanks to @SiKing for the push in the right direction.

这篇关于硒的webdriver测试一个ActiveX控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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