情境:
我有画廊页面,其中不同的图像粘贴在屏幕上,当我 点击一个 图像,花式框打开下一个和上一个按钮,用户可以下一步和后退 查看精美框中的所有图像
问题
在我将鼠标指针物理移动到
之前,花式框不会打开
在测试运行期间选择图像或将鼠标指针设置在屏幕上
在测试运行之前将显示所选图像
WebElement el = driver.findElement(By.xpath("//div[2]/p/a/span"));
Actions builder = new Actions(driver);
builder.moveToElement(el).click();
builder.perform();
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
// following code add to move mouse pointer physically but its also not working
Point coordinates = driver.findElement(By.xpath("//div[2]/p/a/span")).getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinates.getX(),coordinates.getY()+120);
答案 0 :(得分:0)
Webdriver可以在不使用Actions
的情况下点击元素。如果以下代码段适合您,请尝试使用。
WebElement el = driver.findElement(By.xpath("//div[2]/p/a/span"));
el.click();
如果没有,请验证您的xpath一次并发布您获得的错误。
此外,您在执行点击操作后添加了impicit等待。这不会引入任何等待click命令本身。隐式等待与driver
变量的生命周期相关联,理想情况下应在driver
实例化时添加。
如果您需要等待为每个操作自定义的操作,请尝试使用Explicit Waits
。