Syntax error How to press ENTER inside an edit box in Selenium?

How to press ENTER inside an edit box in Selenium?



Selenium gives Enum Key macros to perform the enter action.

Example

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import java.util.List;
public class PressEnter {
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      String url = " https://www.tutorialspoint.com/index.htm";
      driver.get(url);
      driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
      // Keys.ENTER passed through sendKeys() method
      driver.findElement(By.className("gsc-input")).sendKeys("Keys.ENTER");
      driver.close();
   }
}
Updated on: 2020-06-10T13:34:13+05:30

851 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements