webdriver類比滑鼠懸浮

來源:互聯網
上載者:User

標籤:bdr   software   img   ima   except   color   https   int   span   

未經作者允許,禁止轉載!

有時候會遇到這樣的情況,滑鼠停留在某一地區,不需要點擊,懸浮在這一地區的上方就會顯示該地區的下拉框,如

下面將滑鼠停留在“日曆”和“星座”這兩個部分之間來回懸浮,下面是代碼:

package test20161207;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.interactions.Action;import org.openqa.selenium.interactions.Actions;public class test20161207 {    public static void main(String[] args) throws InterruptedException {        // TODO Auto-generated method stub        System.setProperty("webdriver.chrome.driver", "C:\\Training\\Automation\\Software\\drivers\\chromedriver_win32\\chromedriver.exe");        WebDriver driver=new ChromeDriver();        driver.get("https://www.hao123.com/");        driver.manage().window().maximize();        Thread.sleep(3000);                //下面是滑鼠懸浮的完整代碼        WebElement element1=driver.findElement(By.xpath("//*[@id=‘calendarv2‘]/div[1]"));        Actions builder1=new Actions(driver);        Action mouserOverlogin = builder1.moveToElement(element1).build();        mouserOverlogin.perform();        Thread.sleep(2000);                //下面是滑鼠懸浮的簡潔之後的代碼        WebElement element2=driver.findElement(By.xpath("//*[@id=‘hao123-star‘]"));        Actions builder2=new Actions(driver);        builder2.moveToElement(element2).build().perform();        Thread.sleep(2000);            WebElement element3=driver.findElement(By.xpath("//*[@id=‘calendarv2‘]/div[1]"));        Actions builder3=new Actions(driver);        builder3.moveToElement(element3).build().perform();        Thread.sleep(2000);                WebElement element4=driver.findElement(By.xpath("//*[@id=‘hao123-star‘]"));        Actions builder4=new Actions(driver);        builder4.moveToElement(element4).build().perform();        Thread.sleep(2000);    }}

 

 下面是相對來說比較麻煩一點的

先將滑鼠懸浮在1處,出現車輛展示下拉框,然後再將滑鼠懸浮在從第一輛車到最後一輛車

package test20161207;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.interactions.Action;import org.openqa.selenium.interactions.Actions;public class toyota_MouseOver20161207 {    public static void main(String[] args) throws InterruptedException {        // TODO Auto-generated method stub        System.setProperty("webdriver.chrome.driver", "C:\\Training\\Automation\\Software\\drivers\\chromedriver_win32\\chromedriver.exe");        WebDriver driver=new ChromeDriver();        driver.get("http://www.toyota.com/");        driver.manage().window().maximize();        Thread.sleep(3000);                driver.findElement(By.xpath("//*[@id=‘tcom-secondary-nav‘]/ul/li[2]")).click();        Thread.sleep(2000);                //下面是滑鼠懸浮的完整代碼        WebElement element1=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[1]/a[1]"));        Actions builder1=new Actions(driver);        Action mouserOverlogin = builder1.moveToElement(element1).build();        mouserOverlogin.perform();        Thread.sleep(2000);                //下面是滑鼠懸浮的簡潔之後的代碼        WebElement element2=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[2]/a[1]"));        Actions builder2=new Actions(driver);        builder2.moveToElement(element2).build().perform();        Thread.sleep(2000);            WebElement element3=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[3]/a[1]"));        Actions builder3=new Actions(driver);        builder3.moveToElement(element3).build().perform();        Thread.sleep(2000);                WebElement element4=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[4]/a[1]"));        Actions builder4=new Actions(driver);        builder4.moveToElement(element4).build().perform();        Thread.sleep(2000);                WebElement element5=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[5]/a[1]"));        Actions builder5=new Actions(driver);        builder5.moveToElement(element5).build().perform();        Thread.sleep(2000);                WebElement element6=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[6]/a[1]"));        Actions builder6=new Actions(driver);        builder6.moveToElement(element6).build().perform();        Thread.sleep(2000);                WebElement element7=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[7]/a[1]"));        Actions builder7=new Actions(driver);        builder7.moveToElement(element7).build().perform();        Thread.sleep(2000);                WebElement element8=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[8]/a[1]"));        Actions builder8=new Actions(driver);        builder8.moveToElement(element8).build().perform();        Thread.sleep(2000);                WebElement element9=driver.findElement(By.xpath("//*[@id=‘cars-minivan‘]/li[1]/a[1]"));        Actions builder9=new Actions(driver);        builder9.moveToElement(element9).build().perform();        Thread.sleep(2000);            }}

 

webdriver類比滑鼠懸浮

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.