无法使用具有相同类的protactor查找元素

时间:2018-06-29 11:32:59

标签: selenium protractor element

我有一个复选框和两个具有相同类和相同Div的链接。在使用量角器进行自动化测试期间,我想单击复选框,但单击链接。 我正在编写此代码,但无法正常工作,请提供解决方案。 代码:

element(by.id('Remember')).click();

[{enter image description here 1

请找到HTMl代码:-

<div class="input-field">
            <div class="pas_rembr">
              <input name="remember" id="Remember" class="css-checkbox ng-dirty ng-valid-parse ng-touched ng-not-empty ng-valid ng-valid-required" ng-model="rememberMe" type="checkbox" ng-required="true" required="required">
              <!-- <label for="Remember" class="css-label">I agree with the <a class="text_link" target="_blank" ng-href="{{baseUrl}}terms-conditions">Terms & Conditions</a>.</label> -->
              <label for="Remember" class="css-label">I have read and I agree with <a class="text_link" target="_blank" ng-href="/lmd/terms-conditions" href="/lmd/terms-conditions">Terms and Conditions</a> and the <a class="text_link" target="_blank" ng-href="/lmd/privacy" href="/lmd/privacy">Privacy Policy</a> of this site.</label>
            </div>
            <span class="errorForm ng-hide" ng-show="(memberForm.remember.$dirty || submitted) &amp;&amp; ((memberForm.remember.$error.required))">
              <span class="errorForm ng-scope ng-hide" ng-show="memberForm.remember.$error.required" translate="TERAMS_CONDITION_IS_REQUIRED">Terms and condition is required</span>
            </span>
          </div>

2 个答案:

答案 0 :(得分:1)

尝试一下:-

var el = element(by.css('label[for="Remember"]'));
browser.actions().mouseMove(el, {x: 20, y: 3}).click().perform();

答案 1 :(得分:0)

对于您的测试,CSS选择器应为

element = $$('label.css-label > a:nth-child(2)');

这应该能够单击标签元素的第二个a子项。