使用selenium单击具有unicode字符作为其标签的按钮

时间:2013-05-24 15:39:30

标签: xpath selenium unicode

您可以想象,我无法访问网页代码。我需要点击一个下拉按钮,当我查看源时,该按钮的唯一独特功能是它是一个值为▼的INPUT元素

<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

问题是我不能太具体,因为课程&amp; id被重复使用,唯一独特的是▼。

1 个答案:

答案 0 :(得分:0)

我找到了一条似乎有效的xpath:

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

感谢您的建议,@ Pat Meeker!