"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');
未选择国家/地区,并且引发错误,无效的定位器,但是定位器看起来还可以。
有人可以帮助我吗?请
答案 0 :(得分:0)
选择器
'//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"]'
答案 1 :(得分:0)
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','美国'));
答案 2 :(得分:0)
已解决。问题缺少浏览器的定义
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');