0

I've got an HTML page with the following format:

   <select id="name_list">
      <optgroup label="env1">
          <option value="comp1">comp1 details</option>
      </optgroup>
      <optgroup label="env2">
          <option value="comp1">comp1 details</option>
      </optgroup> 
   </select>

And trying to click on the option with value=comp1 which is inside optgroup-env2 specifically. Is there any way to specify this path? Note that both 'options' values are exactly the same under the different 'optgroup' nodes...

Many thanks!

4

1 回答 1

0

您可以像任何其他元素一样定位 optgroup。然后,您可以在该组中搜索您的选项。

browser.optgroup(:label =>'env2').option(:value => 'comp1').select

更新- 看起来 watir-webdriver 中有一个错误阻止上述工作。

在为标签创建定位器时,watir-webdriver 调用以下方法

def should_use_label_element?
  @selector[:tag_name] != "option"
end

对于 optgroup,这将返回 false,这意味着 watir 会查找关联的标签元素(而不是检查属性)。

作为临时解决方法,您可以使用 css:

browser.element(:css => 'optgroup[label="env2"]').option(:value => 'comp1').select

已为此问题创建了一个错误(请参阅问题 219)。

于 2013-09-13T11:18:15.853 回答