Java Appium MobileElement.tap();不适用于移动web的iosSimulator 8.2
我正在使用Java在ios safari上自动测试移动web 一切似乎都设置正确,但appium因错误而崩溃:Java Appium MobileElement.tap();不适用于移动web的iosSimulator 8.2,java,automated-tests,appium,mobile-website,Java,Automated Tests,Appium,Mobile Website,我正在使用Java在ios safari上自动测试移动web 一切似乎都设置正确,但appium因错误而崩溃: uncaughtException: Cannot read property 'x' of undefined 触摸命令在日志中显示如下: info: --> POST /wd/hub/session/1a925d31-d3cd-4231-9698-f7ff4db739fd/touch/perform {"actions":[{"action":"press","option
uncaughtException: Cannot read property 'x' of undefined
触摸命令在日志中显示如下:
info: --> POST /wd/hub/session/1a925d31-d3cd-4231-9698-f7ff4db739fd/touch/perform {"actions":[{"action":"press","options":{"element":"5001"}},{"action":"wait","options":{"ms":1}},{"action":"release","options":{}}]}
info: [debug] Pushing command to appium work queue: "au.getElement('5001').rect()"
info: [debug] Sending command to instruments: au.getElement('5001').rect()
我的代码如下所示:
public void tap(MobileElement element) {
appiumDriver.context(getContext("NATIVE"));
element.tap(1,1);
appiumDriver.context(getContext("WEBVIEW"));
}
protected String getContext(String partial) {
String result = null;
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
if(contextName.contains(partial)){
result = contextName;
}
}
if (result == null){
throw new NoSuchContextException("Could not find requested context");
}
return result;
}
public void tap(MobileElement元素){
appiumDriver.context(getContext(“NATIVE”);
元素。tap(1,1);
appiumDriver.context(getContext(“WEBVIEW”);
}
受保护的字符串getContext(字符串部分){
字符串结果=null;
设置contextNames=driver.getContextHandles();
for(字符串contextName:contextName){
if(contextName.contains(部分)){
结果=上下文名称;
}
}
如果(结果==null){
抛出新的NoSuchContextException(“找不到请求的上下文”);
}
返回结果;
}
我给它喂了一个手机
我可以通过将元素视为WebElement
并执行getlocation()
来获取元素位置,然后我可以使用TouchAction
,这与appium正在执行的操作有关,但位置是超级关闭的,因此我尝试在此处使用mobileeelement
点击()操作
是否有人知道解决方法,或者知道我可能做错了什么?我的网站有很多元素需要点击tap()
当我定义WebElement
,然后移动到本机上下文并使用iosDriver.tap(1,WebElement,1)时,也会发生这种情况代码>在appium端发生相同的崩溃。请尝试以下操作:
AppiumDriver appiumDriver = new AppiumDriver();
String originalContext = appiumDriver.getContext();
Point coordinate = element.getLocation();
Dimension loc = element.getSize();
int centerX = loc.getWidth() / 2 + coordinate.getX();
int centerY = loc.getHeight() / 2 + coordinate.getY();
appiumDriver.context("NATIVE_APP");
appiumDriver.tap(1, centerX, centerY, 2);
appiumDriver.context(originalContext);
问题在于,在本机上下文中,Appium对网页上的webelements没有任何可见性,您需要获得坐标,然后使用带有坐标的Tap方法单击