我需要获取所有匹配 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 column name'
).最后一列标题不直接可见,必须水平滚动才能找到它...表格由angular动态生成。
感谢您的任何建议!
我是一名优秀的程序员,十分优秀!