เราสามารถจำลองการกด Enter ในช่องป้อนข้อความ html ด้วย Selenium webdriver เราจะใช้ความช่วยเหลือของ sendKeys เมธอดและส่ง Keys.ENTER เป็นอาร์กิวเมนต์ของวิธีการ นอกจากนี้เรายังสามารถผ่าน Keys.RETURN เป็นอาร์กิวเมนต์ของวิธีการทำงานเดียวกัน
นอกจากนี้ เราต้องนำเข้า org.openqa.selenium.Keys แพ็คเกจเป็นรหัสสำหรับใช้ กุญแจ ระดับ. ให้เรากด ENTER/RETURN หลังจากป้อนข้อความในช่องป้อนข้อมูลด้านล่าง

ตัวอย่าง
การติดตั้งโค้ดด้วย Keys.ENTER
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
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();
driver.get("https://www.tutorialspoint.com/about/about_careers.htm");
// identify element
WebElement l=driver.findElement(By.id("gsc-i-id1"));
l.sendKeys("Selenium");
// press enter with sendKeys method and pass Keys.ENTER
l.sendKeys(Keys.ENTER);
driver.close();
}
} การติดตั้งโค้ดด้วย Keys.RETURN
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
public class PressReturn{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.tutorialspoint.com/about/about_careers.htm");
// identify element
WebElement l=driver.findElement(By.id("gsc-i-id1"));
l.sendKeys("Selenium");
// press enter with sendKeys method and pass Keys.RETURN
l.sendKeys(Keys.RETURN);
driver.close();
}
}