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

1
  • Add a snippet of HTML.
    – olyv
    CommentedSep 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.

2
  • I am not getting the pop up window after clicking on upload button, thats what i am asking about, unable to open upload window.CommentedSep 22, 2014 at 2:06
  • Also please let me know which firefox version with which selenium version is the best?CommentedSep 22, 2014 at 2:07
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); 
2
  • which firefox version and which selenium-server-standalone file you are using?CommentedSep 21, 2014 at 7:37
  • Firefox 13.XX and Selenium-2.42.2.jarsCommentedSep 21, 2014 at 10:28
0

use below line:

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

1
  • 2
    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.
    – VP.
    CommentedOct 6, 2015 at 13:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.