Find element by attribute

后端 未结 4 1729
鱼传尺愫
鱼传尺愫 2020-11-30 03:37

I am trying to find an element with Attribute. Well, I can find elements with Id, tagName, Xpath and all other predefined methods in Selenium. But, I am trying to write a me

4条回答
  •  旧时难觅i
    2020-11-30 04:19

    You can easily get this task accomplished with CSS.

    The formula is:

    element[attribute='attribute-value']
    

    So if you have,

    
    

    You can find it using:

    By.cssSelector("a[href='mysite.com']");
    

    this works using any attribute possible.

    This page here gives good information on how to formulate effective css selectors, and matching their attributes: http://ddavison.io/css/2014/02/18/effective-css-selectors.html

提交回复
热议问题