定位包含可见文本的元素(忽略格式标签) [英] Locate element which contains visible text (ignoring formatting tags)

查看:24
本文介绍了定位包含可见文本的元素(忽略格式标签)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为搜索结果编写硒测试.搜索结果的代码段使用 标签格式化:

I'm trying to write a selenium test for a search result. The search result's snippet is formatted with <strong> tags:

<li>foo <strong>bar</strong></li>

如何选择所有包含可见文本foo bar"的 lis,即忽略 标签?当然,我可以遍历所有 lis,获取文本并删除 <strong> 标签,但如果仅使用 xpath 就可以,那就更好了.硒溶液也可以.

How do I select all lis containing the visible text "foo bar", i.e. ignoring the <strong> tag(s)? Of course I could iterate over all lis, get the text and remove the <strong> tags, but if it is possible with xpath alone, it would be nicer. A selenium solution would be fine, too.

谢谢

推荐答案

您可以使用 . 用于此目的:

You can use . for this purpose :

//li[.='foo bar']

. 在这种情况下返回上下文元素内的所有文本节点,连接起来.

. in this case returns all text nodes within context element, concatenated.

这篇关于定位包含可见文本的元素(忽略格式标签)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆