isSelected returns false and isChecked shows compi

2019-03-02 06:56发布

问题:

let checkBoxXpath = accessPolicyPage.listCheckBoxXpathS + i + accessPolicyPage.listCheckBoxXpathE;
//element(by.xpath(checkBoxXpath)).click();
expect(element(by.xpath(checkBoxXpath)).isSelected()).toBeTruthy();

in the above code isSelected returns false and if I replace it by isChecked, it shows error as "property 'ischecked' not found on ElementFinder"

How I can overcome this

回答1:

There is nothing called isChecked in Protractor. You can do this by using isSelected.

webdriver.WebElement.prototype.isSelected = function() {
  return this.schedule_(
      new webdriver.Command(webdriver.CommandName.IS_ELEMENT_SELECTED),
      'WebElement.isSelected()');
};

Refer this to more information. Hope this helps. :)