开发者

Capybara - how to test presence of class attribute for nth element

开发者 https://www.devze.com 2023-03-26 22:30 出处:网络
I have a list like this <ul> <li></li> <li .current></li> <li></li>

I have a list like this

<ul>
  <li></li>
  <li .current></li>
  <li></li>
</ul>

and if a user clicks on an li it adopts the class "current". I want to test this in capybara but im wondering how to write the test. I want to be specific in the test by saying the second element should only have the class "current".

i know how to target the second element using xpath i.e //li[2] a开发者_StackOverflow中文版nd i also know how target an element by class //li[@class="current"] but i dont know how to bring them both together to to write this test.


Is this what you want? :)

assert _the_li_element_you_found.node[:class] == "current"
0

精彩评论

暂无评论...
验证码 换一张
取 消