I am new to Selenium Webdriver, i want to open the file upload window after clicking on Browse button but i am not able to open it using webdriver.
Here is my code :
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Login_Page {
static WebDriver driver;
public static void main(String args[])
{
driver = new FirefoxDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 40);
WebDriverWait wait = new WebDriverWait(driver, 40);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.toolsqa.com/automation-practice-form");
driver.findElement(By.id("photo")).click();
}
}
I am not able to see any file upload window.
I am using Firefox 14.0.1 and selenium-server-standalone-2.24.1.jar
Please let me know how can i do it? Thanks
-
Add a snippet of HTML.olyv– olyv2014年09月21日 20:13:02 +00:00Commented Sep 21, 2014 at 20:13
3 Answers 3
I guess you want to upload the file after the click on upload button. Even though you can click on the upload button, which will bring you the pop up window, you can't select the files using selenium calls.
So in order to upload the file, you need to do this:
WebElement uploadButton = driver.findElement(//your strategy) //to the upload button
uploadButton.sendKeys("your full path to the file")
And also you need to use latest Selenium version for your corresponding FireFox browser.
2 Comments
Problem is with your firefox version. In mine this script is working smoothly. Once I had such problem,this script will only make Browse button in focus.What you can do is after getting in focus,Send Enter Key. Add this piece of code after click event.
Actions action = new Actions(driver);
action.sendKeys(Keys.ENTER);
2 Comments
use below line:
driver.findElement(By.xpath(.//*[@id='photo']).click();
1 Comment
Explore related questions
See similar questions with these tags.