【问题】使用webdriver.io 需要实现一个UI自动化输入input 并 回车
pageObeject
import {keyboard} from "../utils/keyboard-mouse-operation"; class CommonPage { get searchInput() { return $('input[name="search"]') } get saveButton() { return $('.portal-button--primary=SAVE') } get deleteButton() { return $('.portal-button--primary=DELETE') } get doneButton() { return $('.portal-button--secondary=DONE') } searchKeyword(keyword){ this.searchInput.click() //this.searchInput.setValue(keyword) this.searchInput.setValue(`${keyword}\n`) // keyboard.press('backspace',80) //browser.keys(['Enter']) // browser.keys("\uE007") browser.pause(5000) } } export default new CommonPage()
【尝试方法1】
自定义工具类进行输入enter,并调用
keyboard.press('backspace',80)
定义工具类 类名为 keyboard-mouse-operation
module.exports.keyboard ={ key: { 'enter': '\ue007', 'backspace': '\u0008', 'esc':'\u001B' }, press(button, num=1){ if (button in this.key){ const actions = [ { "type": "key", "id": "keyboard", "actions": [ {"type": "keyDown", "value": this.key[button]}, {"type": "keyUp", "value": this.key[button]}, ] } ] let i = 0 while(i < num){ browser.performActions(actions) i++ } }else{ console.log("The button isn't defined for the method") } } } module.exports.mouse = { key: { 'left': 0 }, click(button, x=0, y=0, num=1){ if (button in this.key){ const actions = [ { "type": "pointer", "id": "mouse", "parameters": {"pointerType": "mouse"}, "actions": [ {"type": "pointerMove", "duration": 0, "origin": "pointer", "x": x, "y": y}, {"type": "pointerDown", "button": this.key[button]}, {"type": "pointerUp", "button": this.key[button]} ] } ] let i = 0 while(i < num){ browser.performActions(actions) i++ } }else{ console.log("The button isn't defined for the method") } } }
【尝试方法2】
使用框架自带的方法
browser.keys("\uE007");
【尝试方法3】
直接在传参的后面加入回车
element.setValue(`${value}\n`);
标签:webdriver,io,button,enter,actions,key,keyboard,type,browser From: https://www.cnblogs.com/chenxiaomeng/p/16779866.html