0

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

asked Sep 21, 2014 at 7:12
1
  • Add a snippet of HTML. Commented Sep 21, 2014 at 20:13

3 Answers 3

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.

answered Sep 21, 2014 at 10:12
Sign up to request clarification or add additional context in comments.

2 Comments

I am not getting the pop up window after clicking on upload button, thats what i am asking about, unable to open upload window.
Also please let me know which firefox version with which selenium version is the best?
0

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);
answered Sep 21, 2014 at 7:26

2 Comments

which firefox version and which selenium-server-standalone file you are using?
Firefox 13.XX and Selenium-2.42.2.jars
0

use below line:

driver.findElement(By.xpath(.//*[@id='photo']).click();

answered Oct 6, 2015 at 12:39

1 Comment

Please, consider to format your answer properly, add some details to it, avoid posting answers with short content like this, it is always better to have well-explained answers.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.