我必须点击鼠标悬停后生成的图块。我在下面编写了代码,但它仍然无效。
WebElement FrontElement=driver.findElement(By.xpath("//a[@class='sol-itm-bx relative front-app-nm']/span[text()='UI Auto Test12345']"));
WebElement BackElement= driver.findElement(By.xpath("//a[@class='relative back-app-desc']/span[text()='UI Auto Test12345']"));
Actions builder = new Actions(driver);
builder.moveToElement(FrontElement);
builder.perform();
builder.clickAndHold(FrontElement);
BackElement.click();
答案 0 :(得分:2)
要使用Actions()
类,您需要将操作链接在一起。单独的命令将无法以您希望的方式工作。
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.xpath("//a[@class='sol-itm-bx relative front-app-nm']/span[text()='UI Auto Test12345']")))
.moveToElement(driver.findElement(By.xpath("//a[@class='relative back-app-desc']/span[text()='UI Auto Test12345']")))
.click().perform();
注意:为了便于阅读,我将线条分开了。 编辑:'build'到'builder'NullPointerException