定位策略在selenium ide中给出两个结果

时间:2016-06-06 07:57:48

标签: selenium selenium-ide

对于所有复选框和单选按钮,我创建了一个定位器构建器:

LocatorBuilders.add('radio', function(e) {

      var name = e.parentNode.parentNode.getAttribute('name');
      var value = name + '_' + e.parentElement.getAttribute('value');
      var result = 'radio=' + value;
      return result;

});

一个定位策略:

PageBot.prototype.locateElementByRadio = function(locatorString, inDocument, inWindow) {

    var name = locatorString.split('_')[0];
    var value = locatorString.split('_')[1];

    var result = inDocument.querySelector('div[field=' + name +'] label[value=' + value +'] input');

    return result;

}

HTML元素:

<div class="radio" name="radio-example" style="">
    <label class="radio-label" value="male" style="">
         <input class="radio-input" style="" tabindex="1" type="radio">
         <span class="option">Man</span>
     </label>
</div>

这很完美,在我的selenium IDE中就像radio = new_yes 但是当我在收音机上录制一个点击时,我看到了selenium ide中的两个命令。一个带有locater构建器的命令和一个带有verry长xpath的命令,该命令属于复选框中的标签。如何仅从复选框中记录输入字段?而不是标签?

Selenium IDE

1 个答案:

答案 0 :(得分:0)

如果您只想获取radiobutton的定位器,可以使用此定位器

public class Mapper { public static Mapper<T> GetFor<T>(T templateObject) { return new Mapper<T>(); } }

如果您还有其他问题,请与我们联系。