[英]How to hover the mouse from left to right icons in selenium webdriver (Java)?
這是我用來將鼠標從“產品”移動到“查找ATM分支”的代碼(總共有5種Web元素產品,在線申請,付款,銀行付款方式,查找ATM分支 ):
package Advance_SeleniumPackg;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.support.events.internal.EventFiringMouse;
public class Mouse_Movement {
public static void main(String[] args) throws InterruptedException {
WebDriver webdriver=new FirefoxDriver();
EventFiringWebDriver driver=new EventFiringWebDriver(webdriver);
WebListener listener=new WebListener();
driver.register(listener);
EventFiringMouse mouse=new EventFiringMouse(driver,listener);
driver.navigate().to("http://www.icicibank.com/");
Thread.sleep(5000L);
Locatable hoverItem = (Locatable) driver.findElement(By.linkText("Products"));
Locatable hoverItem1 = (Locatable) driver.findElement(By.linkText("Find ATM Branch"));
Coordinates MyTestCoordinates = hoverItem.getCoordinates();
Coordinates MyTestCoordinates1 = hoverItem1.getCoordinates();
try{
mouse.mouseMove(MyTestCoordinates);
mouse.mouseMove(MyTestCoordinates1);
}catch(Throwable t){
System.out.println(t);
}
Thread.sleep(3000L);
}
}
請使用下面的代碼將光標從“產品”標簽移動到“查找ATM分公司”標簽
package SamplePrograms;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class WebDriverSecondProgram {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 100);
driver.get("http://www.icicibank.com");
wait.until(ExpectedConditions.titleContains("Personal Banking"));
Actions hoverOps = new Actions(driver);
hoverOps.moveToElement(driver.findElement(By.xpath(".//a[text()='Products']"))).build().perform();
Thread.sleep(2000);
hoverOps.moveToElement(driver.findElement(By.xpath(".//a[text()='Apply Online']"))).build().perform();
Thread.sleep(2000);
hoverOps.moveToElement(driver.findElement(By.xpath(".//a[text()='Payments']"))).build().perform();
Thread.sleep(2000);
hoverOps.moveToElement(driver.findElement(By.xpath(".//a[text()='Ways to Bank']"))).build().perform();
Thread.sleep(2000);
hoverOps.moveToElement(driver.findElement(By.xpath(".//a[text()='Find ATM Branch']"))).build().perform();
Thread.sleep(2000);
driver.quit();
}
}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.