輸入某個內容后,使用enter鍵進行確認,最開始使用方式為:
driver.findElement(By.xpath("//input[@name='supplier_name'][@id='js_productSupplier']")).sendKeys("輸入內容"); Actions action=new Actions(driver); action.keyDown(Keys.ENTER).perform();
運行時,提示
java.lang.IllegalArgumentException: Key Down / Up events only make sense for modifier keys.
百度了下是說enter不能單獨使用,需要和ctrl或者ALT的鍵配合使用,我的使用是
action
.keyDown(Keys.
ALT
).keyDown(Keys.
ENTER
).perform();
但是還是提示這個key down的錯誤
查看其它API,發現能不能直接使用sendkeys直接輸入發現keys.enter,也可以正常執行回車鍵
driver.findElement(By.xpath("//input[@name='supplier_name'][@id='js_productSupplier']")).sendKeys("輸入內容");
Actions action=new Actions(driver);
action.sendKeys(Keys.
ENTER).build().perform();