Selenium WebDriver c#是否可以附加文件以进行上传 [英] Selenium WebDriver c# Is it possible to attach a file to upload
本文介绍了Selenium WebDriver c#是否可以附加文件以进行上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想附加一个文件进行上传.我正在尝试以下测试,但无法正常工作
I want to attach a file for upload. Part of a test I am attempting the following but it is not working
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"));
推荐答案
只需尝试以下代码
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的文本框上发送sendKeys即可.
It will work. No need to click the browse button. Just sendKeys on the textBox where filePath appears.
这篇关于Selenium WebDriver c#是否可以附加文件以进行上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文