【问题标题】:Selenium WebDriver c# Is it possible to attach a file to uploadSelenium WebDriver c#是否可以附加文件上传
【发布时间】:2016-06-18 08:59:54
【问题描述】:

我想附加一个文件以供上传。作为测试的一部分,我正在尝试以下操作,但它不起作用

1) Enter some details into the input fields    
2) Click Browse on the Web site
3) Enter a file path in the windows popup that appears
4) Click Open on the windows popup
5) Click Apply on the Web site 

Driver.FindElement(By.Id("Name")).SendKeys(name);
Driver.FindElement(By.Id("EmailAddress")).SendKeys(email); 
Driver.FindElement(By.Id("TelephoneNumber")).SendKeys(telephone.ToString());     
Driver.FindElement(By.Name("file")).Click();    
Driver.SwitchTo().ActiveElement().SendKeys("/home/likewise-open/GLOBAL/123/Documents/filename.txt");
Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Driver.FindElement(By.Id("convertButton"));

【问题讨论】:

标签: c# selenium selenium-webdriver


【解决方案1】:

由于 WebDriver 只能处理基于 Web 的交互而不是基于 Windows 的交互, 您将需要 AutoIT 实用程序才能上传或下载并将其集成到 Selenium 脚本中。 AutoIT 是一款免费工具。

【讨论】:

【解决方案2】:

试试这段代码

Driver.FindElement(By.Name("yourUploadFileTextBox")).SendKeys("/home/likewise-open/GLOBAL/123/Documents/filename.txt");
Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Driver.FindElement(By.Id("convertButton"));

它会起作用的。无需单击浏览按钮。只需在 filePath 出现的文本框上发送密钥。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-20
    • 2017-12-09
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多