gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:02:40 24 4
gpt4 key购买 nike

我需要获取所有匹配 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动态生成。

感谢您的任何建议!

最佳答案

您可以使用 Get Matching Xpath Count 引用 Get Matching Xpath Count文档中的关键字以获取更多信息。

关于python - 如何在不使用机器人框架和 python 滚动的情况下获取所有匹配元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43938349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com