我有一个HTML文档(有一个ID为“countries”的DIV,它包含下面的代码),我需要 -
验证选择中的选项。我尝试了这个,但这是无效的。
expect(page).to have_xpath(('// * [@ id =“countries”] // select')[1], :options => ['US CAN GER POL'])
验证第二个选择是否已禁用
确认在第一个选择
确认在第一个选择
在第一个选择
中将所选选项更改为GER<li>
<fieldset>
<select>
<option value="US">USA</option>
<option value="CAN" disabled>Canada</option>
<option value="GER">Germany</option>
<option value="POL" selected>Poland</option>
</select>
<fieldset>
<li>
<li>
<fieldset>
<select disabled>
<option value="US">USA</option>
<option value="CAN">Canada</option>
<option value="GER">Germany</option>
<option value="POL">Poland</option>
</select>
<fieldset>
<li>
醇>
感谢您提供的任何帮助。谢谢!
答案 0 :(得分:1)
警告,我个人仍然使用rspec的should
语法,我也使用css选择器与xpath。我觉得它们更容易阅读。
(1)因为你有两个下拉列表,没有任何特定的ID或类名来识别另一个,我会使用all
来限制你期望的背景
all('#countries select')[0].should have_text('USA Canada Germany Poland')
(2)与上述相同的概念,限制范围。第二个字段集应包含禁用的下拉列表。
all('#countries fieldset')[1].should have_css('select[disabled]')
(3)all('#countries select')[0].should have_css('option[disabled]', :text => 'Canada')
(4)与#3相同,但具有不同的属性和文本
(5)all('#countries select')[0].find('option', :text => 'Germany').click