量角器中的 for 循环在该循环中的最后一个数字处给出错误"No element found using locator: By(css selector, span.ng-binding)"



我一直从AngularJS应用程序测试开始。我需要对选择一些症状后出现的问卷进行多个答案。问题是文本或广播按钮作为输入字段,他们的问题是带有2个广播按钮或3个无线电按钮

//First method Code Giving the same error 
// Questionnaire
obj.questionnaire_row.each(function(question) {
  question.element(by.model("data.answer")).click().sendKeys(d.Easycirmmail.answers);
});
//Second method for answering the questions
function questions(index) {
  obj.questionnaire_row.get(index).element(by.css("span.ng-binding")).getText().then(function(value) {
    console.log(value);
  });
  obj.questionnaire_row.get(index).element(by.model("data.answer")).click().sendKeys(d.Easycirmmail.answers);
}
obj.questionnaire_row.count().then(function(qcount) {
  console.log("Question " + qcount);
  for (var i = 0; i <= qcount; i++) {
    console.log(i);
    questions(i);
    if (i == qcount - 1) {
      break;
    }
  }
});

这些是NG-Repeater中提出的问题


//这是控制台输出:

Started
Count 14
Master 2
Master 1
Master 11
Master 0
Master 4
Count 15
Symptoms 7
Symptoms 1
Symptoms 6
Symptoms 1
Symptoms 14
Symptoms 3
Symptoms 7
Symptoms 8
Symptoms 12
Symptoms 3
Symptoms 8
Symptoms 11
Symptoms 3
Symptoms 10
Symptoms 10
Question 45
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Q) How long has it been since the pain started?
Q) Did he suffer a traumatism?
[10:55:48] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:49] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Did the patient have alcoholic drinks?
[10:55:49] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:49] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Did he stay too long in the sun or in a very hot place?
[10:55:49] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:49] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Did the patient have any sexual intercourse?
[10:55:50] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:50] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Did he suffer from it in the past?
[10:55:50] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:50] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Is there nausea or vomit?
[10:55:50] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:50] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Is he shivering?
[10:55:50] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:51] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Are there spots, blisters or other lesions on the genitals?
[10:55:51] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:51] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Is there any penis secretion?
[10:55:51] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:51] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Is there any swelling of the glands or pain in the groins region?
[10:55:52] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:52] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Are the internal organs suspected of having been damaged?
[10:55:53] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:53] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Describe the traumatism: bruise, contusion, abrasion, excoriation, superficial wound, deep penetrating wound
Q) Is the patient constipated
[10:55:54] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:54] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Does he have diarrhoea?
[10:55:54] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:54] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Is the urine red?
[10:55:54] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:55] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Is there any blood in the urine?
[10:55:55] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:55] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Does the patient have any trouble passing water?
[10:55:55] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:55] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Is any blood coming from the patient’s mouth?
[10:55:56] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:56] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Was there a loss of consciousness or a feeling of fainting?
[10:55:56] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:56] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Does the patient have acclereted heartbeats and cold perspiration?
[10:55:56] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:56] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Does he have a feeling of nausea or vomit?
[10:55:56] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:57] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Has he got breathing difficulties, a lack of air?
[10:55:57] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:57] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
Q) Take a picture
Q) Are the faeces black (like coffee grounds)?
[10:55:57] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
[10:55:58] W/element - more than one element found for locator by.model("data.answer") - the first result will be used
F

//And the error is as follows:
Failures:
1) Easy Cirm Testing  4.Actions Easy Cirm Mail
  Message:
    Failed: No element found using locator: By(css selector, span.ng-binding)
  Stack:
    NoSuchElementError: No element found using locator: By(css selector, span.ng-binding)
        at elementArrayFinder.getWebElements.then (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractorbuiltelement.js:814:27)
        at ManagedPromise.invokeCallback_ (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1376:14)
        at TaskQueue.execute_ (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
        at TaskQueue.executeNext_ (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
        at asyncRun (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2927:27)
        at C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
        at process._tickCallback (internal/process/next_tick.js:68:7)Error
        at ElementArrayFinder.applyAction_ (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractorbuiltelement.js:459:27)
        at ElementArrayFinder.(anonymous function).args [as getText] (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractorbuiltelement.js:91:29)
        at ElementFinder.(anonymous function).args [as getText] (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractorbuiltelement.js:831:22)
        at questions (C:Users3 CubeEasy-Cirm-AutomationListCrewPage.js:257:93)
        at C:Users3 CubeEasy-Cirm-AutomationListCrewPage.js:266:29
        at ManagedPromise.invokeCallback_ (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1376:14)
        at TaskQueue.execute_ (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
        at TaskQueue.executeNext_ (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
        at asyncRun (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2927:27)
        at C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
    From: Task: Run it("4.Actions Easy Cirm Mail") in control flow
        at UserContext.<anonymous> (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:94:19)
        at C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:64:48
        at ControlFlow.emit (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibevents.js:62:21)
        at ControlFlow.shutdown_ (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2674:10)
        at shutdownTask_.MicroTask (C:Users3 CubeAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2599:53)
    From asynchronous test:
    Error
        at Suite.<anonymous> (C:Users3 CubeEasy-Cirm-AutomationListCrewPage.js:150:5)
        at Object.<anonymous> (C:Users3 CubeEasy-Cirm-AutomationListCrewPage.js:132:1)
        at Module._compile (internal/modules/cjs/loader.js:688:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
        at Module.load (internal/modules/cjs/loader.js:598:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

// Questionnaire
async function questionsfunction(index) { //async and awaits keyword is used to complete the function as called in the loop and then after i must be increased.
  await obj.questionnaire_row.get(index).element(by.css("span.ng-binding")).getText().then(function(value) {
    console.log(value);
  });
  console.log("Index: " + index);
  await obj.questionnaire_row.get(index).element(by.model("data.answer")).click().sendKeys(d.GenerateEvent.answers);
}
obj.questionnaire_row.count().then(function(qcount) {
  console.log("total Question " + qcount);
  console.log("Question " + (qcount - 1));
  for (let i = 0; i <= qcount - 2; i++) { //Used "-2" for the loop, Reason as the Last object in the ng-repeat is not having any question and answer
    console.log(i);
    questionsfunction(i);
  }
});

最新更新