1

I need to automate the "Browse" button click from Selenium.

enter image description here

For this, I have tried

driver.findElement(By.xpath("//*[@id=\"dnn_ctr383_View_filename\"]")).click();

and

driver.findElement(By.cssSelector("Css path")).click();

Both gives me org.openqa.selenium.NoSuchElementException: Unable to locate element: exception.

I have seen this link here where the author suggest to use AutoIT, but in step 2, the script, the author has created is for IE. Can someone please suggest, how I can automate the "Browse" button click in firefox?

Any help is much appreciated.

4
  • Do you just need to select a file, or something else as well? Commented Jan 10, 2013 at 12:35
  • Try to click on the span above. Commented Jan 10, 2013 at 12:37
  • First I need to get the selector window opened after I press the "Browse" button. After that, select a file and upload. Select and upload is secendory. Bringing the browse window on click of "Browse" is the first thing Commented Jan 10, 2013 at 12:37
  • 1
    Can you copy the xpath (full) of the button from the firebug. Commented Jan 10, 2013 at 12:55

2 Answers 2

3

Directly send the file path to the id, like so

driver.findElement(By.id("dnn_ctr383_View_filename")).sendKeys("C:\\path\\to\\file");

The above step is the answer for your first two steps

  1. Click on Browse
  2. Select a file to upload

For the third step(click upload), looking at the screen capture I do not see any button which says "Upload". So just click "Save" and I assume that your file will successfully get uploaded.

Sign up to request clarification or add additional context in comments.

Comments

0

There are two things that u need to consider here:

  1. Clicking the browser button: Usually handled by an alert or popup, if the driver is not able to find the element by xpath(which u have acquired from firebug or chrome's inspect element) you should consider looking for iframes in the page source. If an element is in a different frame altogether , u need to switch frames in order to find the element like this

    WebElement frame = driver.findElementById("name_of_iframe");

    driver.switchTo().frame(fr);

now you can find your element using xpath or css selector like u did. Once completed u can move out of the frame by:- driver.switchTo().defaultContent();

  1. Uploading the file from desktop: Since selenium works only on the html in the browser session u invoked from the driver, it can't perform operations on your desktop.Once you are able to click the browser button u can use Auto it(works only on windows) or Sikuli(works with mac, linux, windows and even android) to simulate your events based on the position of your upload button.

Hope this helps

Comments

Your Answer

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.