问题
I have an element with 3 classes which I need to find with selenium
<button style="padding:2px 7px; background-color:#4caeea"
class="btn btn-xs btn-custom" </button>
I could not find it with : By.classname("btn btn-xs btn-custom")
I do not want to use xpath & cssSelector . What other options do I have ?
回答1:
This By.classname("btn btn-xs btn-custom")
will not work, as it contains multiple spaces which means it is combination of 3 classes.
You will have to switch to css selector or xpath , I do not know why you have mentioned that you do not want to use both of them.
However, If you are interest to use css selector :
You can try this :
By.cssSelector("btn.btn-xs.btn-custom")
If you go by precedence :
- ID
- name
- classname
- linkText
- partialLinkText
- tagName
- css selector
- xpath
来源:https://stackoverflow.com/questions/51204668/how-to-find-element-that-has-multiple-class-in-selenium