這是我用於將鼠標從「產品」移動到「查找ATM分支」的代碼(總共有5個網絡元素產品,在線申請,付款,銀行方式,查找ATM分支):如何在selenium webdriver(Java)中將鼠標從左到右的圖標懸停?
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);
}
}
你是否運行過你的代碼?你得到了什麼? –
是的,我運行了我的程序,但它在產品和Find ATM分支上盤旋。其實我正在尋找一個定義源和目的地後自行運行的程序。 – Samy