日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

selenium测试(Java)--鼠标事件(六)

發布時間:2025/4/5 java 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 selenium测试(Java)--鼠标事件(六) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

鼠標操作:

1.右擊

2.雙擊

3.拖到

4.懸停

?

?

1 package com.test.mouse;2 3 import java.io.File;4 5 import org.openqa.selenium.By;6 import org.openqa.selenium.WebDriver;7 import org.openqa.selenium.WebElement;8 import org.openqa.selenium.firefox.FirefoxDriver;9 import org.openqa.selenium.firefox.FirefoxProfile; 10 import org.openqa.selenium.interactions.Actions; 11 12 public class MouseOperation { 13 14 public static void main(String[] args) { 15 FirefoxProfile profile = new FirefoxProfile( 16 new File("C:\\Users\\XXXX\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\a6xwo0b1.default")); 17 WebDriver driver = new FirefoxDriver(profile); 18 19 driver.get("http://c37.yunpan.360.cn"); 20 driver.manage().window().maximize(); 21 waitTime(5000); 22 23 driver.findElement(By.xpath("//*[@id='infoPanel']/a[2]")).click(); 24 waitTime(3000); 25 26 driver.findElement(By.xpath("//*[@id='tbText']")).click(); 27 WebElement testitem = driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[2]")); 28 testitem.click(); 29 waitTime(3000); 30 31 // 左擊實現(和元素的click類似) 32 Actions action = new Actions(driver); 33 WebElement test1item = driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[2]")); 34 action.click(test1item).perform(); 35 waitTime(5000); 36 37 // 返回上一級 38 driver.findElement(By.xpath("//*[@id='crumb']/div/span[1]")).click(); 39 waitTime(5000); 40 41 // 雙擊實現 42 new Actions(driver).doubleClick(driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[2]"))).perform(); 43 waitTime(5000); 44 45 // 返回上一級 46 driver.findElement(By.xpath("//*[@id='crumb']/div/span[1]")).click(); 47 waitTime(5000); 48 49 // 懸停 到更多按鈕實現 50 new Actions(driver).moveToElement(driver.findElement(By.xpath("//*[@id='topPanel']/ul/li[3]/a"))).perform(); 51 52 // 拖動實現 53 driver.findElement(By.xpath("//*[@id='tbPic']")).click(); 54 WebElement begin = driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[1]")); 55 WebElement end = driver.findElement(By.xpath("//*[@id='list']/li[2]/div[2]/span[1]")); 56 new Actions(driver).dragAndDrop(begin, end).perform(); 57 58 // 右擊實現 59 // 這里雖然使用的是元素任然是test1item,但是頁面刷新過后需要重新定位 60 // 參考http://docs.seleniumhq.org/exceptions/stale_element_reference.jsp 61 driver.findElement(By.xpath("//*[@id='tbText']")).click(); 62 new Actions(driver).contextClick(driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[2]"))) 63 .perform(); 64 waitTime(5000); 65 66 driver.findElement(By.xpath("//*[@id='x-yp-3']/ul/li[4]/a/span")).click(); 67 waitTime(5000); 68 69 driver.quit(); 70 71 } 72 73 static public void waitTime(int time) { 74 75 try { 76 Thread.sleep(time); 77 } catch (InterruptedException e) { 78 // TODO Auto-generated catch block 79 e.printStackTrace(); 80 } 81 } 82 83 }

注:perform()的作用是 執行所有Actions中存儲的行為。

總結

以上是生活随笔為你收集整理的selenium测试(Java)--鼠标事件(六)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。