编辑:
好的,我已经通过jquery小部件检查了代码及其渲染。
END
我正在尝试将光标移动到<a \>
,但问题是在我将鼠标指针物理移动到所选图像上之前,该元素不会被渲染。
如何移动鼠标悬停在<a \>
上以选择/点击?
FF version 20
Selenium WebDriver version: 2.31.2.0
当前代码
Actions actions = new Actions(driver);
int locationX = Convert.ToInt32(ratingElementDiv[i].Location.X);
int locationY = ratingElementDiv[i].Location.Y;
actions.MoveToElement(WaitForElement(By.CssSelector(starElement)), locationX, locationY).Click().Perform();
我没有看到任何行动......有什么帮助吗?
答案 0 :(得分:8)
行动由3个步骤组成。
Actions builder = new Actions(driver);
Point location ratingElementDiv[i].getLocation();
builder.MoveToElement(WaitForElement(By.CssSelector(starElement)), location.X, location.Y).click();
(我不确定点击次数)
Action selectLink = builder.build();
selectLink.perform();
试试这个并告诉我你是否还有问题。
答案 1 :(得分:3)
让我们说当你点击“选择你的测试”时,你会看到多个元素的下拉列表(ABC,DEF,GHI等)。您想要选择ABC并单击它。使用以下。
driver.findElement(By.linkText("Select Your Test")).click();
new Actions(driver).moveToElement(driver.findElement(By.linkText("ABC"))).click().perform();
答案 2 :(得分:3)
此链接可以帮助您。它解释了键盘和鼠标事件。
http://www.guru99.com/keyboard-mouse-events-files-webdriver.html
答案 3 :(得分:0)
对我有用
//定位一個按鈕
WebElement button = driver.findElement(By.xpath("//div[@class='page-button']"));
//new 一個移動滑鼠的物件
Actions clickAction = new Actions(driver).click(button);
//執行
clickAction.build().perform();