Selenium WebDriver and browsers select file dialog
来源:互联网 发布:linux 系统添加wifi 编辑:程序博客网 时间:2024/05/29 09:47
If you are trying to select a file for upload Selenium 2 supports HTML file inputs. For example:
HTML
<input type="file" id="uploadhere" />
Selenium Code
IWebElement element = driver.FindElement(By.Id("uploadhere"));element.SendKeys("C:\\Some_Folder\\MyFile.txt");
Basically you "type" (with SendKeys
) the full file path to the file input element. Selenium handles the file selection dialog for you.
However if you want to manipulate an arbitrary file selection dialog, then like Anders said, you have to go outside of Selenium.
Here is another solution using remotewebdriver, it works like magic and I loved it.
Here is the class I have:
driver.findElementByLinkText("Upload Files").click();driver.setLogLevel(Level.ALL);System.out.println(driver.getCurrentUrl());WebElement element = driver.findElement(By.xpath("//input[@name='file_1']"));LocalFileDetector detector = new LocalFileDetector();//Now, give the file path and see the magic :) String path = "D://test66T.txt";File f = detector.getLocalFile(path);((RemoteWebElement)element).setFileDetector(detector);element.sendKeys(f.getAbsolutePath());//now click the button to finishdriver.findElementByXPath("//html/body/div[9]/div[1]/a/span").click();
- Selenium WebDriver and browsers select file dialog
- Selenium WebDriver history and today
- ASP.NET Interfaces: Internet File Select and Upload Dialog
- Selenium - Differences between WebDriver.close(), WebDriver.dispose() and WebDriver.quit()
- Selenium WebDriver get ,getScreenshotAs(OutputType.FILE);
- Selenium - The architecture differences between Selenium RC and Selenium WebDriver
- Selenium-WebDriver API Commands and Operations
- read and select file
- selenium webdriver学习(八)------------如何操作select下拉框
- selenium webdriver学习:如何操作select下拉框
- selenium webdriver学习(八)------------如何操作select下拉框
- Selenium WebDriver
- selenium webdriver
- Selenium WebDriver
- Selenium WebDriver
- selenium webdriver
- Selenium WebDriver
- Selenium Webdriver
- 史蒂夫 乔布斯(Steve Jobs)在斯坦福大学2005年毕业典礼上的演讲
- 0002 沙箱1
- 从汇编看volatile
- git 图解
- C++类模板的三种特化
- Selenium WebDriver and browsers select file dialog
- Android平台Native开发与JNI机制详解
- JSTL实现for(int i)循环
- 六十四、基础框架(二十二)文件操作-基本文件操作
- Activity生命周期详解
- 亲。。。。。。我不存在!
- 信息检索和网络数据挖掘领域论文技术基础
- 自定义水平的进度条(效果很炫)ProgressBar
- selenium2 and webdriver Alert