selenium-javaApi
作者:互联网
本文中没有的请查看下面链接
https://blog.csdn.net/qq_29817481/article/details/101052012?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-8.pc_relevant_antiscanv2&spm=1001.2101.3001.4242.5&utm_relevant_index=11
1. 模拟鼠标操作. perform() 执行所有Actions中存储的行为
// 新建一个action
Actions action = new Actions(driver);
// 鼠标左键单击
action.click().perform();
// 鼠标左键双击
action.doubleClick(WebElement).perform();
// 鼠标左键按下
action.clickAndHold(WebElement).perform();
// 鼠标移动到元素(鼠标悬停)
action.moveToElement(WebElement).perform();
// 元素右键点击
// 在Actions类中的鼠标右键方法是个已知的bug,因为它能点击右键出现菜单,但无法选择右键菜单选项,因此该方法了解即可!
action.contextClick(WebElement).perform();
// 将目标元素拖拽到指定的元素上
action.dragAndDrop(webElement1,webElement2);
// 拖拽到某个坐标然后松开
action.dragAndDrop(webElement, xOffset, yOffset);
// 释放鼠标
action.release().perform();
2. 模拟键盘操作
sendKeys(Keys.BACK_SPACE) 回格键(BackSpace)
sendKeys(Keys.SPACE) 空格键(Space)
sendKeys(Keys.TAB) 制表键(Tab)
sendKeys(Keys.ESCAPE) 回退键(Esc)
sendKeys(Keys.ENTER) 回车键(Enter)
sendKeys(Keys.CONTROL,‘a’) 全选(Ctrl+A)
sendKeys(Keys.CONTROL,‘c’) 复制(Ctrl+C)
sendKeys(Keys.CONTROL,‘x’) 剪切(Ctrl+X)
sendKeys(Keys.CONTROL,‘v’) 粘贴(Ctrl+V)
sendKeys(Keys.F1) 键盘 F1
sendKeys(Keys.F12) 键盘 F12
Actions action = new Actions(driver);
//按下control键
action.keyDown(Keys.CONTROL);
//松开control键
action.keyUp(Keys.CONTROL);
action.keyDown(Keys.CONTROL).keyDown(Keys.ALT).keyDown("A").keyUp(Keys.CONTROL).keyUp(Keys.ALT).keyUp("A").perform();
action.sendKeys(Keys.CONTROL+"a").perform();
action.sendKeys(Keys.CONTROL, Keys.ALT, "A").perform();
标签:CONTROL,relevant,Keys,selenium,perform,javaApi,action,sendKeys 来源: https://www.cnblogs.com/xudong5273/p/16080415.html