It is possible to handle condition from CSS style in selenium?

Viewed 82

To check which input is enable, in our DOM structure(Knockout JS) there is no specific property, which says the button is enable..

Its handled by one of the CSS property, of ::before class :

enter image description here

CSS: {content: "\f013";}

HTML:

<div data-bind="foreach: XXXXXX ">
 <div class=".col-xs-3 col-sm-3 col-md-3 -setting-radio" data-bind="attr: " > 
  <label class="radio-position radio-inline " data-view="widgets/input/radio/view" data-active-view="true" style="">
        <input class="-widgets-input-radio-check" id="radio" type="radio" data-bind="Enable: enable, value: value, checked: checked" value="1" name="FS">
  <span class="-radio-label"></span> 
  <span class="-widgets-input-radio-text" data-bind="html: data">Global</span>
  </label>  
 </div>

 <div class=".col-xs-3 col-sm-3 col-md-3 -setting-radio" data-bind="attr: " > 
  <label class="radio-position radio-inline" data-view="widgets/input/radio/view" data-active-view="true" style=""> 
    <input class="-widgets-input-radio-check" id="radio" type="radio" data-bind="Enable: enable, value: value, checked: checked" value="2" name="FS">
    <span class="-radio-label"> </span>
    <span class="-widgets-input-radio-text" data-bind="html: data">Capital</span> 
  </label>
 </div>  
</div> 

How can we achieve it ?

1 Answers

There is a special method for this in selenium, named value_of_css_property The name differs on the language you use, but the idea is the same.

As I understand from your question you can use it like as in the below example:

assert driver.find_element_by_css_selector('css_locator').value_of_css_property("content") == "\f013"

HTML is not enough, you need to check which CSS properties are changed as well. You can use it to for waits and asserts. I use computed tab for this: enter image description here

Related