Reputation: 249
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.
Upvotes: 3
Views: 3208
Reputation: 364
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);
Upvotes: 1
Reputation: 193088
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 :
Here you can find a detailed discussion on the following.
Upvotes: 5
Reputation: 215
This is what I have been using.
driver.pressKeyCode(AndroidKeyCode.ENTER);
Upvotes: 1