Selenium WebDriver to test an ActiveX Control

余生颓废 提交于 2019-12-13 03:38:25

问题


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.

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();
            }
        }
    }

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.

Any thoughts?

Thanks!


回答1:


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);
            }
        }
    }

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



来源:https://stackoverflow.com/questions/24145054/selenium-webdriver-to-test-an-activex-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!