这是我用于将鼠标从“产品”移动到“查找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