How to verify an attribute is present in an element using Selenium WebDriver?

前端 未结 6 2099
旧巷少年郎
旧巷少年郎 2020-12-31 02:14

I have many radio buttons on my screen. When a radio button is selected, it has an attribute of checked. When the radio button is not selected, the checked attribute is not

6条回答
  •  不思量自难忘°
    2020-12-31 02:24

    Checkboxes can tricky sometimes, because the attribute checked may not be followed by an attribute value.

    If you're only concerned with the presence of the attribute, a simple check would look like this:

     boolean hasAttr_css = driver.findElementsByCssSelector("#input_id[checked]").isEmpty();
    

提交回复
热议问题