gpt4 book ai didi

java - Sikuli - 单击元素不适用于 Java API,但可以在 IDE 中使用 - WPF 应用程序

转载 作者:行者123 更新时间:2023-12-02 05:03:28 26 4
gpt4 key购买 nike

我正在评估用于测试基于 WPF 的应用程序的工具。我目前正在尝试使用 Java API 来使用 Sikuli。当我尝试从 Java 代码中单击某个对象时,鼠标光标移至该对象并且该对象突出显示,但是单击操作不起作用,因为预期的菜单未打开。但 click() 方法返回状态 1。如果我从 Sikuli IDE 中进行单击,则效果很好。我尝试了 1.0.1 版本以及 nightly build。这是我的代码:

@Test
public void testLogin() {
Screen s = new Screen();
try {
s.wait(Constants.overflowMenu);
System.out.println(s.click(Constants.overflowMenu));
s.wait(Constants.signInMenuOption, 5);
} catch (FindFailed e) {
Assert.fail(e.getMessage());
}
}

我做错了什么?

最佳答案

试试这个代码,它对我有用。它的作用是检查图像,单击它,然后在屏幕上再次检查该图像,如果它仍然存在,则再次单击。

屏幕屏幕 = new Screen(); 模式pattern = null;

    try
{
pattern = new Pattern(imageLocation);
screen.wait(pattern,30);
screen.click(pattern);
System.out.println("First Attempt To Find Image.");
}
catch(FindFailed f)
{
System.out.println("Exception In First Attempt: " +f.getMessage());
System.out.println("FindFailed Exception Handled By Method: ClickObjectUsingSikuli. Please check image being used to identify the webelement. supplied image: " +imageLocation);
Assert.fail("Image wasn't found. Please use correct image.");
}

Thread.sleep(1000);

//In case image/object wasn't clicked in first attempt and cursor stays in the same screen, then do second atempt.
if(screen.exists(pattern) != null)
{
try
{
screen.getLastMatch().click(pattern);
System.out.println("Second Attempt To Find Image.");
System.out.println("Object: " +imageLocation + " is clicked successfully.");
}
catch(FindFailed f)
{
System.out.println("Exception In Second Attempt: " +f.getMessage());
System.out.println("FindFailed Exception Handled By Method: ClickObjectUsingSikuli. Please check image being used to identify the webelement. supplied image: " +imageLocation);
}
}

关于java - Sikuli - 单击元素不适用于 Java API,但可以在 IDE 中使用 - WPF 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28028506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com