1

I am using selenium to upload a file.

driver.findElement (By.id("lll")).click(); 
// Now, a pop up window shows up
// The window has a button "Choose File" on focus
Robot robot = new Robot();
robot.mouse // how can I click this button ? I tried KeyPress(Enter) but this click on "OK" by default

Also, the "Choose File" button has its xpath but I do not know how to switch from the browser to the pop up window

Any suggestions?

Thanks

Aleksei Nikolaevich
  • 325
  • 3
  • 15
  • 40

2 Answers2

3

Sounds like it's a standard "Browse...." file upload element.

In which case, you should (being the key word) not have to use any screen manipulation tools like the Robot class.

You should just be able to send the element a path to the file you want. Such as:

driver.findElement(By.id("id")).sendKeys("C:\the\path");

If this is the case, do not click the element to open the popup window.

Arran
  • 24,648
  • 6
  • 68
  • 78
1

Try robot.mousePress(int i) and robot.mouseRelease(int i).

A previous post with example code: How can I make Robot press and hold a mouse button for a certain period of time?

Community
  • 1
  • 1
Substance586
  • 76
  • 1
  • 5