Selenium选择器学习

Selenium选择器推荐用CSS选择器

 

If you don’t care about the ordering of child elements, you can use an attribute selector in selenium to choose elements based on any attribute value. A good example would be choosing the ‘username’ element of the form above without adding a class.

We can easily select the username element without adding a class or an id to the element.

 

按照ID:

div#elementId ...

按照属性:
XPATH: //input[@name='username']
CSS: input[name='username']

We can even chain filters to be more specific with our selectors.

XPATH: //input[@name='login'and @type='submit']
CSS: input[name='login'][type='submit']

or选择:用逗号分割即可
css: div.class1,div.class2

 

posted on 2022-09-07 10:50  秀泉  阅读(82)  评论(0编辑  收藏  举报

导航