Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

protractor - No element found using locator: by.model() error

I'm writing an end to end test using protractor for my application. I'm seeing errors of the form:

No element found using locator: By.model("address.fullName") error. 

The corresponding protractor code which is throwing this error is:

var angularElement = element(By.model("address.fullName"));
angularElement.sendKeys("test");

However I'm able to fetch this element using:

var angularElement = element(By.xpath('//input[@ng-model="address.fullName"]'));

HTML snippet:

input ng-model="address.fullName" type="text" class="control-input ng-pristine ng-invalid ng-invalid-required" size="40" name="fullName" ng-class="{ 'required-field': isInformationSubmitted }" required=""

I'm not sure why this is happening. Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I've had some close errors, my error occurred cause the item was not shown on the page or protractor did not finish updating its model so before using the variable i:
-maximized the page: If the element was unseen browser.manage().window().maximize();
-opened the list the item was in:
-waiting for protractor to finish updating it's model:

var ptor = protractor.getInstance();
ptor.waitForAngular();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...