全部产品
云市场

rpa.ctrl_visitor34

更新时间:2019-09-18 15:39:30

版本要求:客户端在3.4.0及以上ie、win32使用,chrome仍然使用rpa.**ctrl_visitor.

目录

rpa.ctrl_visitor34

提供在运行时动态修改控件树的一组方法
注意:所有的控件树变更都只在运行时有效,并不会真正的修改应用数据(不会持久化变更信息)

add

add(self, name, value)
name : 控件名称
value : 控件元对象

该方法会在控件树中添加一个新控件

  1. raw = [{"optionProps": [{"value": "IEFrame", "name": "class", "pattern": "Equal"}], "props": [{"value": "\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053", "name": "title", "pattern": "Equal"}, {"value": "iexplore", "name": "app", "pattern": "Equal"}], "name": "Window", "type": "wnd"}, {"optionProps": [{"value": "text", "name": "type", "pattern": "Equal"}, {"value": "wd", "name": "name", "pattern": "Equal"}, {"value": "s_ipt nobg_s_fm_hover", "name": "class", "pattern": "Equal"}], "props": [{"value": "kw", "name": "id", "pattern": "Equal"}], "name": "input", "type": "ie"}]
  2. page = rpa.ie.create("www.baidu.com")
  3. rpa.ctrl_visitor34.add("输入", raw)
  4. page.input("输入", "添加控件完成")

get

get(self, name)
name : 控件名称

根据控件名称获取控件元对象,返回dict类型

  1. raw = rpa.ctrl_visitor.get('输入框')
  2. # 此时获取到的内容要通过json.dumps(raw)转至json进行解析。

remove

remove(self, name)
name : 控件名称

根据控件名称删除控件

  1. rpa.ctrl_visitor.remove('输入框')
  2. page = rpa.ie.create('www.baidu.com')
  3. page.input('输入框', 'Alibaba') # raise SDKError, 指定控件不存在

update

update(self, name, value)
name : 控件名称
value : 控件元对象

更新指定控件的元数据

  1. page = rpa.ie.create("www.baidu.com")
  2. news = rpa.ctrl_visitor34.get("新闻")
  3. news[2]["props"][0]["value"] = "视频"
  4. print(json.dumps(news))
  5. rpa.ctrl_visitor34.update("新闻", news)
  6. url1 = page.attr("新闻", "href")

例如:录制百度输入框。

  1. # 获取到的输入框属性信息如下:
  2. new = [{"optionProps": [{"value": "IEFrame", "name": "class", "pattern": "Equal"}], "props": [{"value": "\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053", "name": "title", "pattern": "Equal"}, {"value": "iexplore", "name": "app", "pattern": "Equal"}], "name": "Window", "type": "wnd"}, {"optionProps": [{"value": "text", "name": "type", "pattern": "Equal"}, {"value": "wd", "name": "name", "pattern": "Equal"}, {"value": "s_ipt nobg_s_fm_hover", "name": "class", "pattern": "Equal"}], "props": [{"value": "kw", "name": "id", "pattern": "Equal"}], "name": "input", "type": "ie"}]
  3. # 将new内容放置https://www.json.cn/#进行json解析
  4. # 获取到的值可通过json解析器解析到如下内容。(json所使用引号都为双引号)

image.png