How To Upload a File Using Selenium Webdriver


Without Using AUtoIt we upload an image using this post.

Solution: Dealing with Dialog Box:

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();
String path = “D://test66T.txt”;
File f = detector.getLocalFile(path);
((RemoteWebElement)element).setFileDetector(detector);
element.sendKeys(f.getAbsolutePath());
driver.findElementByXPath(“//html/body/div[9]/div[1]/a/span”).click();

Advertisements

One thought on “How To Upload a File Using Selenium Webdriver

  1. krishnam August 10, 2015 / 12:38 am

    its not working

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s