我想附加一个要上传的文件。作为测试的一部分,我尝试执行以下操作,但不起作用
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"));发布于 2016-03-05 22:45:59
由于WebDriver只能处理基于web的交互,而不能处理基于windows的交互,因此您需要使用AutoIT实用程序来上传或下载并将其集成到Selenium脚本中。AutoIT是一个免费的工具。
发布于 2016-03-10 15:00:46
试一下这段代码
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的textBox上使用sendKeys即可。
https://stackoverflow.com/questions/35799213
复制相似问题