Aleksei Nikolaevich
Aleksei Nikolaevich

Reputation: 325

How to click a mouse on the button on focus?

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

Upvotes: 1

Views: 555

Answers (2)

Substance586
Substance586

Reputation: 96

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?

Upvotes: 1

Arran
Arran

Reputation: 25076

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.

Upvotes: 3

Related Questions