问题
So I'm writing automation tests for Ionic 2/Angular 2 and I have DOM element that looks like this
<ion-segment-button class="segment-button segment-activated" role="button" tappable="" value="orders" aria-pressed="true">
and I've created a page object that looks like this:
ordersButton: element(by.css('[value="orders"]')),
and in my spec file my test step looks like so
expect((orders.header.ordersButton).element(by.css('.segment-activated')).isPresent()).toBeTruthy();
this returns false and I can't figure out why. Any ideas?
回答1:
You may need to wait for the presence of the element:
var EC = protractor.ExpectedConditions;
var button = orders.header.ordersButton;
var segmentActivated = button.element(by.css('.segment-activated'));
browser.wait(EC.presenceOf(segmentActivated), 5000);
expect(segmentActivated.isPresent()).toBe(true);
来源:https://stackoverflow.com/questions/35921828/why-does-chaining-selectors-in-protractor-return-false-when-using-ispresent