在不使用AutoIT的情况下使用C#处理Selenium中的选择文件窗口 [英] Handling Choose file window in Selenium with C# without using AutoIT

查看:130
本文介绍了在不使用AutoIT的情况下使用C#处理Selenium中的选择文件窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用selenium将文件上传到网站,当单击选择文件"时会打开一个本机窗口,因此,我一直在使用AutoIT,它在进行并行执行时似乎不太可靠. 由于我将Selenium与C#结合使用,因此我想找到一些解决方案,通过该解决方案可以处理该Native窗口,但是我找不到任何解决方案,请有人可以告诉我一些可靠的方法来执行此特定的自动化操作.

I am trying to upload files into a website using selenium which when Clicked on Choose file opens a Native windows, so for this purpose I have been using AutoIT which seems not very reliable when I go for parallel execution. Since I am using Selenium with C# I thought of finding some solution through which I can handle that Native window but I am unable to find any solution please can anybody tell me some reliable way to do this particular automation.

推荐答案

这对我有用,因此希望对您有用.我在这里以扩展方法使用它,但是您可以在常规方法中将其用作/.因此,这使用C#库在对话框中输入路径,并在完成后按Enter.

This worked for me so hopefully it'll work for you. I use it in an extension method here, but you can use as/in a normal method. So this uses C# libraries to enter the path in the dialog and presses enter when done.

            string idPath = "C:/text.txt"; //Path to the file you are trying to upload
            var button = driver.FindElement(By.Id("blah"));

            button.Click()
            driver.WaitOnAPage(1); //simple wait method

            SendKeys.SendWait(@idPath); //this code sends the path to the file upload dialog
            CommonMethods.WaitOnAPage(1);//simple wait method

            SendKeys.SendWait(@"{Enter}"); //simulates pressing enter button 

这篇关于在不使用AutoIT的情况下使用C#处理Selenium中的选择文件窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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