量角器检查单选按钮

时间:2018-08-16 06:47:26

标签: protractor

我想检查量角器脚本中的单选按钮,并且html如下:

<input type="radio" ng-model="relation.type" value="personal" class="ng-valid ng-dirty ng-valid-parse ng-touched" name="7">

我如何编写一个使单选按钮在单选按钮列表中的另一个选择上的表达式?我不想选择的另一个按钮如下所示:

<input type="radio" ng-model="relation.type" value="employee" class="ng-pristine ng-untouched ng-valid" name="8">

所以两者之间唯一的是“值”。

3 个答案:

答案 0 :(得分:0)

您可以这样使用。

element.all(by.model('relation.type')).get(1).getAttribute('value');
element.all(by.model('relation.type"')).get(2).getAttribute('value');
element.all(by.model('relation.type')).first().getAttribute('value');
element.all(by.model('relation.type"')).last().getAttribute('value');

另请参阅量角器文档here

答案 1 :(得分:0)

也许是这样?

    var expectedRadio = element.all(by.model('relation.type'));
    expectedRadio.each((eachRadio) => {
        eachRadio.getAttribute('value').then((valueText) => {
               if (valueText == "personal")
               {
                //Do what you need
               }
        }); 
    });

答案 2 :(得分:0)

试试这个:

   try {
        let btn = element(by.xpath('/html/body/app-root/app-login/div[3]/label[2]'));
         browser.executeScript('arguments[0].click()', btn).then(async() => {
            console.log(' Radio Btn has been clicked.');
        });
       } catch (error) {
        console.log('Button is not clickable due ' + error);
      }