提问人:LearnToGrow 提问时间:11/16/2023 最后编辑:LearnToGrow 更新时间:11/16/2023 访问量:34
如何通过 Xpath 查找包含列表中文本的元素
How to find an element by Xpath that contains a text in a list
问:
我在 python 上使用 selenium。 我的情况是搜索一个元素,其中它的 xpath 包含列表中的文本之一:
string_list =[text1, text2, text3, ..]
# this is the straightforward solution but it does not work.
# convert text in the component to lower as the list contains lower case string.
predicates = [f"contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '{text}')" for text in string_list]
xpath = "//*[" + " or ".join(predicates) + "]"
popup = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, xpath)))
答: 暂无答案
评论