我有在下拉选项选择一个代码,它通过。但页面上没有变化。我有一个普通的下拉菜单:要选择从国家下拉国家下拉列表和状态的国家。
我想我什么都试过计算器上的建议。但是我错过了什么?
此代码是普通的:
<div class="input-holder">
<select name="country" id="country" class="jcf-hidden">
<option value="GBR">United Kingdom</option>
<option value="USA" selected="selected">United States</option>
我的代码是:
it("should edit dropdown", () => {
let country = element(by.id("country"));
let countryOptions = country.all(by.tagName("option"));
let state = element(by.id("state_select"));
let stateOptions = state.all(by.tagName("option"));
countryAndStateSelection();
function countryAndStateSelection() {
countryOptions.getText().then(text => {
if(text === "United States"){
countryOptions.get(217).click(); //UK
stateOptions.get(19).click();
expect(countryOptions.getText()).toEqual("United Kingdom");
}else{
countryOptions.get(218).click(); //USA
stateOptions.get(5).click();
}
});
}
看起来,你有问题,从下拉菜单中选择选项。这是正确的。你不打开下拉,所以valeus是不可见的,但。
在这里,你有一点清理代码:
it("should edit dropdown", () => {
let country = element(by.id("country"));
let state = element(by.id("state_select"));
countryAndStateSelection('United States', 'Alaska');
// add your expect here
function countryAndStateSelection(countryToSelect, stateToSelect) {
selectCountry(countryToSelect);
selectState(stateToSelect);
}
function selectCountry(countryToSelect) {
country.click();
element(by.cssContainingText('#country option'), countryToSelect).click();
}
function selectState(stateToSelect) {
state.click();
element(by.cssContainingText('#state_select option'), stateToSelect).click();
}
});
尝试下面的一个
let country = element(by.id("country"));
let state = element(by.id("state_select"));
//To select country
country.click();
element(by.cssContainingText('#country>option', 'User country name here')).click();
browser.sleep(2000);
state.click();
element(by.cssContainingText('#state_select>option', 'user State Name')).click();
browser.sleep(2000);
希望它可以帮助你