1

可以想象,我无法访问网页代码。我需要单击一个下拉按钮,当我查看源代码时,该按钮的唯一独特之处在于它是一个 INPUT 元素,其 VALUE 为 ▼</p>

<input class="dijitReset dijitInputField dijitArrowButtonInner" type="text" role="presentation" readonly="readonly" tabindex="-1" value="▼ "></input>

这就是我所要做的。当我尝试使用符号本身 (▼) 时,我的代码会引发语法错误,所以我想一些 unicode 值 (U+25BC) 会在这里按顺序排列,但我无法让它工作。

这是 HTML:

<div id="widget_iopri" class="dijit dijitReset dijitInline dijitLeft dijitTextBox dijitComboBox dijitValidationTextBox" role="combobox" widgetid="iopri" aria-expanded="false">
 <div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" role="presentation" data-dojo-attach-point="_buttonNode, _popupStateNode" popupactive="true">
  <input class="dijitReset dijitInputField dijitArrowButtonInner" type="text" role="presentation" readonly="readonly" tabindex="-1" value="▼ "></input>
 </div>
 <div class="dijitReset dijitValidationContainer">
  <input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" type="text" role="presentation" readonly="readonly" tabindex="-1" value="Χ "></input>
 </div>
 <div class="dijitReset dijitInputField dijitInputContainer">
  <input id="iopri" class="dijitReset dijitInputInner" type="text" aria-haspopup="true" role="textbox" data-dojo-attach-point="textbox,focusNode" autocomplete="off" aria-required="true" tabindex="0" aria-invalid="false" value="idle" aria-owns="iopri_popup"></input>
  <input type="hidden" name="iopri" value="3"></input>
 </div>
</div>

我试过了:

//div[@id='widget_iopri']/div[@data-dojo-attach-point='_buttonNode']
//div[@id='widget_iopri']/div[@class='dijitDownArrowButton']/input[@class='dijitArrowButtonInner']
//div[@id='widget_iopri']/div[@class='dijitDownArrowButton']/input

问题是我不能太具体,因为类和 id 在任何地方都被重复使用,唯一独特的是 ▼。

4

1 回答 1

0

我发现了一个似乎可以工作的 xpath:

find(:xpath, "//div[@id='widget_iopri']/div[@data-dojo-attach-point='_buttonNode, _popupStateNode']/input").click

感谢您的建议,@Pat Meeker!

于 2013-05-24T17:13:20.827 回答