我们正在使用Appium自动化react本机iOS应用程序。我们正在使用PageFactory设计模式。对于单击元素,这是我使用的代码:
-
正在等待元素可见。
-
点击元素
public Boolean waitUntilVisible(WebElement element)
{
try {
wait.until(ExpectedConditions.visibilityOf(element));
return true;
}catch (Exception e)
{}
return false;
}
public boolean click(WebElement element)
{
//Click on the element and return true if successful and false if unsuccessful.
try
{
waitUntilVisible(element);
element.click();
} catch (Exception e) {}
return false;
}
整体执行似乎花费了太多时间。根据我的理解,waitUntilVisible会一直等到元素的isDisplayed()变为真。
当我们使用PageFactory时,我假设元素标识发生两次。
1.在检查可见度之前,应首先识别元件。
2.单击之前,将再次标识相同的元素。
由于我们在许多领域使用xpath,元素识别通常需要更长的时间。对于简单的点击,相同的元素会被识别两次,这会进一步增加时间。
我想知道存储已识别元素的任何解决方案,这样它就不会再次花费时间来识别它。
所以我修改了我的代码如下:
public WebElement waitUntilVisible(WebElement element)
{
try {
return wait.until(ExpectedConditions.visibilityOf(element));
}catch (Exception e)
{}
return null;
}
public boolean click(WebElement element)
{
//Click on the element and return true if successful and false if unsuccessful.
try
{
WebElement remoteElement = waitUntilVisible(element);
remoteElement.click();
} catch (Exception e) {}
return false;
}
这种方法似乎不能节省时间。
有没有其他方法可以缩短执行时间。
注意:我们使用WebElement而不是IOSElement,这样在桌面自动化中使用的相同代码也可以在IOS自动化中使用。