Unable to get an element via query on attribute(containing hyphens) value using an XPATH

旧巷老猫 提交于 2021-02-11 12:23:06

问题


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

Example that works fine.

<span data-one="containingOnlyOneHyphen"> </span>
XPATH = '//*[@data-one="containingOnlyOneHyphen"]' (Works Completely Fine)

Example that doesn't work.

<span data-one-two="containingTwoHyphen"> </span>
XPATH = '//*[@data-one-two="containingTwoHyphen"]' (Does not work :/ )

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,

Hassan Mehmood


回答1:


Have you tried using cssSelector for this ?

span[data-one-two=containingTwoHyphen]

works well, according to me. Tested via jsfiddle.net and chrome developer options search.



来源:https://stackoverflow.com/questions/35825197/unable-to-get-an-element-via-query-on-attributecontaining-hyphens-value-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!