【问题标题】:I have select button scenario ,where I have "Country" field when I click on that I see select options.I need to click on US我有选择按钮场景,当我点击时我有“国家”字段,我看到选择选项。我需要点击美国
【发布时间】:2019-03-31 12:05:21
【问题描述】:
  "ng-reflect-positions": "[object Object],[object Object",
  "ng-reflect-offset-y": "0",
  "ng-reflect-min-width": null,
  "ng-reflect-backdrop-class": "cdk-overlay-transparent-backdr",
  "ng-reflect-scroll-strategy": "[object Object]",
  "ng-reflect-open": "false",
  "ng-reflect-has-backdrop": "",
  "ng-reflect-lock-position": ""
  }-->
</mat-select>
<span class="mat-select-placeholder ng-tns-c44-247 ng-star-inserted"
      style="">Country</span>

这是美国选项的 HTML

<span class="mat-option-text"> United States </span>
<mat-option _ngcontent-c43="" class="mat-option ng-star-inserted mat-active" 
            role="option" ng-reflect-value="230" tabindex="0" id="mat-option-2454" 
            aria-selected="false" aria-disabled="false">
            <!--bindings={"ng-reflect-ng-if": "false"}-->
  <span class="mat-option-text"> United States </span>
  <div class="mat-option-ripple mat-ripple" mat-ripple="" ng-reflect-disabled="false" 
        ng-reflect-trigger="[object HTMLElement]">
  </div>
</mat-option>
<span class="mat-option-text"> United States </span>

我在尝试

     var country=element(by.xpath('//input[@placeholder="Country"]'));
     browser.actions();
     actions.mouseMove(country);
     browser.actions.click().perform();
     browser.sleep('3000');
     var us=element(by.xpath('//span[@class="mat-option-text"][text()=" 
     United States "]'));
     browser.actions().mouseMove(us).perform();


       var select = element(by.xpath('//span[@mat-select- 
       placeholder ng-tns-c44-174 ng-star-inserted"][text()="Country"]'));
       select.$('[value="230"]').click();
       browser.sleep('6000');

它没有选择国家,并抛出错误 not valid locator,但 locator 看起来没问题。

有人可以帮帮我吗。请谢谢

【问题讨论】:

  • 它没有选择国家,并抛出错误 not valid locator,但 locator 看起来没问题。
  • 请将其添加到您的问题中,而不是作为评论,谢谢!

标签: javascript angularjs automation protractor qa


【解决方案1】:

选择器

'//span[@mat-select-placeholder ng-tns-c44-174 ng-star-inserted"][text()="Country"]'

缺少双引号。也许你的意思是:

'//span[@class="mat-select-placeholder ng-tns-c44-174 ng-star-inserted"][text()="Country"]'

【讨论】:

  • 对,我用的是'//span[@class="mat-select-placeholder ng-tns-c44-174 ng-star-inserted"][text()="Country"] '
【解决方案2】:
   var country=element(by.xpath('//input[@placeholder="Country"]'));
     browser.actions();
     actions.mouseMove(country);
     browser.actions.click().perform();
     browser.sleep('3000');

       var select = element(by.cssContainingText('.mat-option-text', 'United States '));
       select.click();
       browser.sleep('6000');

我已将定位器替换为 css。试试上面的代码。希望对你有帮助

var select = element(by.cssContainingText('.mat-option-text', 'United States'));

【讨论】:

    【解决方案3】:

    Solved.Problem 缺少浏览器的定义

            var country=element(by.xpath('//input[@placeholder="Country"]'));
            browser.actions();
            browser.actions.mouseMove(country);
            browser.actions.click().perform();
            browser.sleep('3000');
            var us=element(by.xpath('//span[@class="mat-option-text"][text()=" 
            United States "]'));
         browser.actions().mouseMove(us).perform();
    
    
       var select = element(by.xpath('//span[@mat-select- 
       placeholder ng-tns-c44-174 ng-star-inserted"][text()="Country"]'));
       select.$('[value="230"]').click();
       browser.sleep('6000');
    

    【讨论】:

      猜你喜欢
      • 2022-01-26
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多