无法通过使用 XPATH 查询属性(包含连字符)值来获取元素
我在使用 XPATH 获取具有属性的元素时遇到了一个非常奇怪的场景.问题是,如果属性中包含多个连字符,则 Selenium 无法找到该元素.我正在使用 Python 和 Selenium 2.52.0
I'm facing a very weird scenario in getting an element having an attribute using an XPATH. The problem is that if the attribute contains more than one Hyphens in it then Selenium is unable to find that element. I am using Python and Selenium 2.52.0
工作正常的示例.
<span data-one="containingOnlyOneHyphen"> </span>
XPATH = '//*[@data-one="containingOnlyOneHyphen"]' (Works Completely Fine)
不起作用的例子.
<span data-one-two="containingTwoHyphen"> </span>
XPATH = '//*[@data-one-two="containingTwoHyphen"]' (Does not work :/ )
到目前为止,我对这个问题的理解是 Selenium 无法根据包含超过 1 个连字符的属性找到元素.
So far my understanding with this issue is that Selenium is unable to find element based on attribute having more than 1 hyphens in it.
如果您能指导我有关此问题的任何信息,那就太好了.我几乎什么都试过了,但都失败了.
It would be great if you can guide me anything regarding this issue. I've almost tried everything but failed.
谢谢&亲切的问候,
Thanks & kind Regards,
哈桑·马哈茂德
您是否尝试过为此使用 cssSelector ?
Have you tried using cssSelector for this ?
span[data-one-two=containingTwoHyphen]
据我所知,效果很好.通过 jsfiddle.net 和 Chrome 开发人员选项搜索进行测试.
works well, according to me. Tested via jsfiddle.net and chrome developer options search.