標籤: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類比滑鼠懸浮