=
=
1.模拟键盘事件
- Actions action = new Actions(driver);
- action.keyDown(Keys.CONTROL);
- action.keyDown(Keys.SHIFT);
- action.keyDown(Keys.ALT);
- action.keyUp(Keys.CONTROL);
- action.keyUp(Keys.SHIFT);
- action.keyUp(Keys.ALT);
- action.keyDown(Keys.SHIFT).sendKeys("adc").perform();
源码api:
public Actions keyDown(Keys theKey) {
return this.keyDown((WebElement)null, theKey);
}
public Actions keyDown(WebElement element, Keys theKey) {
this.action.addAction(new KeyDownAction(this.keyboard, this.mouse, (Locatable)element, theKey));
return this;
}
2.鼠标:
鼠标左键:鼠标左键就是普通的click()函数
鼠标右键:
- Actions action = new Actions(driver);
- action.contextClick(driver.findElement(By.id("query"))).perform();
3.指定元素上方进行鼠标悬浮
- <html>
- <head>
- <meta http-equiv="Content-type" content="text/html;charset=gb2312"/>
- <script language="javascript">
- function shownone()
- {
- document.getElementById('div1').style.display="none";
- }
- function showBlock()
- {
- document.getElementById('div1').style.display="block";
- }
- </script>
- <style type="text/css">
- <!--#div1{
- position:absolute;
- width:200px;height:115px;
- z-index:1;
- left 28px;top:34px;background-color:#0033CC;
- }-->
- </style>
- </head>
- <body onload="shownone()">
- <div id ="div1"></div>
- <a onmouseover="showBlock()" onmouseout="shownone()" id="link1">鼠标指过来</a>
- <a onmouseover="showBlock()" onmouseout="shownone()" id="link2">鼠标指过来</a>
- </body>
- </html>
selenium代码
- WebElement link1 =driver.findElement(By.xpath("//a[@id='link1']"));
- WebElement link2 = driver.findElement(By.xpath("//a[@id='link2']"));
- new Actions(driver).moveToElement(link1).perform();
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- new Actions(driver).moveToElement(link2).perform();
=
=