谈谈Appium中获取IOS系统中界面元素的解决办法

最近在做移动端的自动化测试,用的是大众化的Appium框架,遇到了一个问题,在IOS系统跑时,点击文本框类型的控件,没有封装好的方法支持输入,像Android中的setText 方法,下面是Appium源码

  1. package io.appium.android.bootstrap.handler;  
  2.   
  3. import com.android.uiautomator.core.UiDevice;  
  4. import com.android.uiautomator.core.UiObjectNotFoundException;  
  5. import io.appium.android.bootstrap.*;  
  6. import org.json.JSONException;  
  7.   
  8. import java.util.Hashtable;  
  9.   
  10. /**  
  11.  * This handler is used to set text in elements that support it.  
  12.  *   
  13.  */  
  14. public class SetText extends CommandHandler {  
  15.   
  16.   /*  
  17.    * @param command The {@link AndroidCommand} used for this handler.  
  18.    *   
  19.    * @return {@link AndroidCommandResult}  
  20.    *   
  21.    * @throws JSONException  
  22.    *   
  23.    * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.  
  24.    * bootstrap.AndroidCommand)  
  25.    */  
  26.   @Override  
  27.   public AndroidCommandResult execute(final AndroidCommand command)  
  28.       throws JSONException {  
  29.     if (command.isElementCommand()) {  
  30.       // Only makes sense on an element  
  31.       try {  
  32.         final Hashtable<String, Object> params = command.params();  
  33.         final AndroidElement el = command.getElement();  
  34.         String text = params.get("text").toString();  
  35.         Boolean pressEnter = false;  
  36.         if (text.endsWith("\\n")) {  
  37.           pressEnter = true;  
  38.           text = text.replace("\\n", "");  
  39.           Logger.debug("Will press enter after setting text");  
  40.         }  
  41.         final Boolean result = el.setText(text);  
  42.         if (pressEnter) {  
  43.           final UiDevice d = UiDevice.getInstance();  
  44.           d.pressEnter();  
  45.         }  
  46.         return getSuccessResult(result);  
  47.       } catch (final UiObjectNotFoundException e) {  
  48.         return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,  
  49.             e.getMessage());  
  50.       } catch (final Exception e) { // handle NullPointerException  
  51.         return getErrorResult("Unknown error");  
  52.       }  
  53.     } else {  
  54.       return getErrorResult("Unable to set text without an element.");  
  55.     }  
  56.   }  
  57. }  
这是Android系统的源码,关于IOS的赋值操作要用什么方法呢?不吝指教

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值