Showing posts with label file upload with webdriver. Show all posts
Showing posts with label file upload with webdriver. Show all posts

Handle File uploading using Webdriver.

We can handle this using java script or by send sendKeys()function:
 
 
1. Using sendKeys():
 
 WebElement upload = driver.findElement(By.id("fileUp"));
        upload.sendKeys("c:/darkbulb.jpg");
        driver.findElement(By.id("submit")).click(); 
 
2. Using Javascript:
 
 WebElement upload = driver.findElement(By.id("fileUp"));
((JavascriptExecutor)driver).executeScript("arguments[0].style.visibility = 'visible';
 arguments[0].style.height = '1px'; arguments[0].style.width = '1px';
 arguments[0].style.opacity =
 1", upload );