3
String str1 = sheet1.getRow(i).getCell(0).getStringCellValue();
String str2 = sheet1.getRow(i).getCell(1).getStringCellValue();

driver2.findElement(By.xpath("//android.widget.EditText[@text='Start - press enter to drop marker']")).clear();
driver2.findElement(By.xpath("//android.widget.EditText[@text='Start - press enter to drop marker']")).sendKeys(str1);
driver2.sendKeyEvent(AndroidKeyCode.ENTER);


driver2.findElement(By.xpath("//android.widget.EditText[@text='End - press enter to drop marker']")).clear();
driver2.findElement(By.xpath("//android.widget.EditText[@text='End - press enter to drop marker']")).sendKeys(str2);

driver2.findElement(By.xpath("//android.widget.Button[@index='1']")).click();

I want to press enter key from phone keyboard in selenium, I used a method called sendKeyEvent but it is not working, can anyone suggest me how to press enter key from phone keyboard in selenium.

vindev
  • 2,240
  • 2
  • 13
  • 20
shivam
  • 249
  • 1
  • 5
  • 18

3 Answers3

5

As per your comment :

  • To press Enter you can use :

    WebElement.sendKeys(Keys.ENTER);
    
  • To press Return you can use :

    WebElement.sendKeys(Keys.RETURN);
    
  • As you wanted to press it on the phone keyboard you can use :

    WebElement.sendKeys(Keys.KEYCODE_NUMPAD_ENTER);
    

Here are the helpful JavaDoc links :

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

You can try any of the below code:

ApplicationSetup.driver.getKeyboard().pressKey(Keys.ENTER);
ApplicationSetup.driver.getKeyboard().sendKeys(Keys.ENTER);
ApplicationSetup.driver.getKeyboard().sendKeys(Keys.RETURN);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Indrapal Singh
  • 364
  • 1
  • 2
  • 13
1

This is what I have been using.

driver.pressKeyCode(AndroidKeyCode.ENTER);
bsk
  • 196
  • 1
  • 7