-1

I click on a web element using xpath and a confirmation window pops up. I just need to press enter on selenium. I tried this:

WebElement.sendKeys(Keys.RETURN);

I got this error from the type WebElement:

Cannot make a static reference to the non-static method sendKeys(CharSequence...)

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
forgivennn
  • 85
  • 1
  • 10
  • 1
    That doesn't really have anything in particular to do with Selenium. Did you Google the error to make an effort to understand what it is, why it's happening, and if there's a similar question with a solution you might be able to use? – tnw Sep 09 '15 at 18:15

1 Answers1

0

In order to press enter key on pop up, first switch to popup using getWindowHandles() and later pass in the enter key using Actions() interface. Here's how to do it -

String subWindowHandler = null;
Actions action = new Actions(webDriverInstance);
Set<String> windowHandler = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = windowHandler.iterator();
while (iterator.hasNext()){
    subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler); //switch to pop up
//Perform your actions on the pop up
action.sendKeys(Keys.RETURN).perform(); //press enter key

Hope this helps.

giri-sh
  • 6,934
  • 2
  • 25
  • 50