我很难找到正确的语法来在下拉列表中选择一个选项,使用rails/capibara/selenium进行测试。以下是HTML页面的检查输出
<select id=”select_test” name=”select_test”>
<option value =””>Month</option>
<option value =”1”>January</option>
<option value =”9”>September</option>
</select>
<button type="button" data-toggle="dropdown" data—id="select_test" title="Month">
<div class="filter-option">
<div class="filter-option-inner">
<div class="filter-option-inner-inner">Month
</div>
</div>
</div>
</button>
我尝试了两种方法:
方法1:
find(‘[title=Month]’).click
find("[value='9']").click
方法2:
Select 'September', from: select_test, visible: :all
两种方法都给我错误
Element <select id='select_test' class="" name=select_test"> is not clickable at point (189,175) because anohter element <div class="filter-option-inner-inner">obscures it
有人以前见过这个,可以帮我找到正确的语法吗?
非常感谢。
查看HTML中带有文本的元素的value属性"九月";是";9〃;所以正确的CSS应该是option[value=’9’]
,但是在这种情况下,您确实应该使用select
。您得到undefined local variable variable
错误是因为您需要将字符串传递给from
,否则ruby会将其解释为您试图调用未定义的方法
select 'September', from: 'select_test'