问题
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