Rspec 测试密码的输入

Rspec 测试密码的输入,rspec,capybara,Rspec,Capybara,我试图测试查看密码按钮的功能,并测试我已经插入的密码。我想这将是容易的部分,困难的部分是实际点击按钮查看密码。我使用rspec来运行测试,使用水豚来与mozilla firefox交互。这是密码字段的代码,以及位于密码字段中的查看按钮 <span class="input-password-toggle-label" data-toggle="true" data-label-show="anzeigen" data-label-hide="verbergen" data-icon-sho

我试图测试查看密码按钮的功能,并测试我已经插入的密码。我想这将是容易的部分,困难的部分是实际点击按钮查看密码。我使用rspec来运行测试,使用水豚来与mozilla firefox交互。这是密码字段的代码,以及位于密码字段中的查看按钮

<span class="input-password-toggle-label" data-toggle="true" data-label-show="anzeigen" data-label-hide="verbergen" data-icon-show="<i class=&quot;icon icon-lg d-inline-block&quot;><svg xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 24 24&quot; class=&quot;d-inline-block&quot; height=&quot;100%&quot; preserveAspectRatio=&quot;xMaxYMax meet&quot; width=&quot;100%&quot;>
      <path d=&quot;M 12 5 C 6 5 1.3875 11.10625 1.1875 11.40625 C 0.8875 11.80625 0.8875 12.19375 1.1875 12.59375 C 1.3875 12.89375 6 19 12 19 C 18 19 22.6125 12.89375 22.8125 12.59375 C 23.1125 12.19375 23.1125 11.80625 22.8125 11.40625 C 22.6125 11.10625 18 5 12 5 z M 12 7 C 14.8 7 17 9.2 17 12 C 17 14.8 14.8 17 12 17 C 9.2 17 7 14.8 7 12 C 7 9.2 9.2 7 12 7 z M 12 9.5 C 10.619288 9.5 9.5 10.619288 9.5 12 C 9.5 13.380712 10.619288 14.5 12 14.5 C 13.380712 14.5 14.5 13.380712 14.5 12 C 14.5 10.619288 13.380712 9.5 12 9.5 z&quot;></path>
    </svg></i>" data-icon-hide="<i class=&quot;icon icon-lg d-inline-block&quot;><svg xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 24 24&quot; class=&quot;d-inline-block&quot; height=&quot;100%&quot; preserveAspectRatio=&quot;xMaxYMax meet&quot; width=&quot;100%&quot;>
      <path d=&quot;M22.8,11.4C22.6,11.1,18,5,12,5S1.4,11.1,1.2,11.4c-0.3,0.4-0.3,0.8,0,1.2C1.4,12.9,6,19,12,19s10.6-6.1,10.8-6.4 C23.1,12.2,23.1,11.8,22.8,11.4z M12,17c-2.8,0-5-2.2-5-5c0-2.8,2.2-5,5-5s5,2.2,5,5C17,14.8,14.8,17,12,17z&quot;></path>
    </svg></i>" style="display: inline;" title="verbergen"><i class="icon icon-lg d-inline-block"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="d-inline-block" height="100%" preserveAspectRatio="xMaxYMax meet" width="100%">
      <path d="M22.8,11.4C22.6,11.1,18,5,12,5S1.4,11.1,1.2,11.4c-0.3,0.4-0.3,0.8,0,1.2C1.4,12.9,6,19,12,19s10.6-6.1,10.8-6.4 C23.1,12.2,23.1,11.8,22.8,11.4z M12,17c-2.8,0-5-2.2-5-5c0-2.8,2.2-5,5-5s5,2.2,5,5C17,14.8,14.8,17,12,17z"></path>
    </svg></i>
</span>


如果有人有任何想法,我将不胜感激。

因为您的HTML在属性中存储了元素,因此很难准确地读取哪些是元素而不是字符串,以及您希望单击哪些元素。在将来发布问题时,更好地格式化HTML会有所帮助。为此,我认为您正在尝试单击外部span元素中当前附加的元素(我假设它在状态更改时被交换)。您可以使用一个基本的CSS选择器来实现这一点

find('span.input-password-toggle-label i').click

那你到底有什么问题?我不知道如何点击ok,那个视图,什么的,按钮或者什么的,实际上可以看到字母而不是***这确实有效,谢谢你,我会在发布问题时尝试改进我的HTML格式