微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在不使用机器人框架和python滚动的情况下获取所有匹配元素?

我需要将所有符合xpath的元素列入列表而不需要滚动到所有元素,因为我永远不知道是否真的需要滚动(取决于监视器的分辨率和列的宽度也可以由开发人员更改)我会不知道在哪里滚动,因为我正在检查列的存在,在某些情况下,正确的结果也是列不存在…

我在测试中使用这些函数获取标题列表:

Get all columns of table ${table}
    ${columns_loc}=  replace substring placeholder ${GRID_HEADERS}  ${table}
    @{locators}=   Get Webelements    ${columns_loc}
    ${result}=       Create List
    :FOR   ${locator}   in    @{locators}
    \       ${name}=    Get Text    ${locator}
    \       Append To List  ${result}  ${name}
    [Return]   ${result}

Check column ${column} is visible
   ${headers2}=  Get all values
   ${res}=  value is in list   ${headers2}   ${column}
   run keyword if    ${res}==False  fail  wrong columns displayed
...                  else  pass execution

我也试过用这个:

def dict_elements(self, xpath):
    elements = self.get_library_instance()._element_find(xpath, False, True)
    headers_map = {}
    if elements is not None:
        for index, element in enumerate(elements):
            headers_map[element.text] = index
        return headers_map
    return None

def list_elements(self, xpath):
    dict = self.dict_elements(xpath)
    return dictionary_keys_to_list(dict)

Get all columns of table ${table}
    ${columns_loc}=  replace substring placeholder ${GRID_HEADERS}  ${table}
    @{cols}=  list elements  ${columns_loc}

但是两个变量都返回9列 – 这是正确的,实际上有9列,但最后一列是EMPTY(仅返回u”)而不是元素的实际文本(如u’last列名’).最后一个标题不能直接显示,它必须水平滚动才能到达它…
该表由angular动态生成.

谢谢你的建议!

解决方法:

您可以使用获取匹配Xpath计数有关详细信息,请参阅文档中的Get Matching Xpath Count关键字.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐