WebDriver-------頁面中的滾動條怎麼滾動,並對隱藏的元素賦值

 下面是我在爬文過程中找到的關於action的操作,不好意思直接拿來用了,   原文地址Link
     Actions action = new Actions(driver);
     action.keyDown(Keys.NUMPAD1).perform();
     action.keyUp(Keys.NUMPAD1).perform();
執行時返回如下錯誤:java.lang.IllegalArgumentException: Key Down / Up events only make sense for modifier keys......
原因:原來這兩個函數只支持“modifier keys”
擴充:
1、順便了解了一下什麼是modifier keys:原來是指鍵盤中ctrl、shift、alt等需要跟其他鍵一起使用纔有作用的鍵。
2、那非轉義鍵我們怎麼用呢?可使用sendKeys函數。
     action.sendKeys(Keys.NUMPAD1).perform();
3、組合用法:
     action.keyDown(Keys.CONTROL).sendKeys(Keys.F5).keyUp(Keys.CONTROL).perform();

下面是我想到的關於頁面中的滾動條怎麼滾動,並給隱藏的元素賦值
public void inputMoney(String input) throws Exception {
chrome.dr.findElements(By.xpath("//*[@id=\"recharge_paylist\"]/input"));
for (int i = 1; i < 11; i++) {
chrome.dr.findElement(By.xpath("//*[@id=\"recharge_paylist\"]/div[" + i + "]/input")).sendKeys(input);
chrome.clickBtnByXpath("//*[@id=\"recharge_paylist\"]/div[1]/label");
new Actions(chrome.dr).sendKeys(Keys.DOWN).perform();
}


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章