2017-09-15 4 views
1

현재 임의로 표시된 요소가있는 페이지가 있습니다. 그 동안, 난 상태 함수를 만든 : 요소가 화면에 표시됩니다요소가없는 경우 조건부 함수를 추가 할 때 오류가 발생합니다.

this.checkDropdownPresent = function (dropdownLocator, chooseOption) { 
    dropdownLocator.isPresent().then(function(element) { 
     if (element) { 
      let select = dropdownLocator; 
      select.element(by.cssContainingText('option', chooseOption)).click(); 
     } 
    }); 
}; 

, 괜찮 일하고와 각도기가 상호 작용을하지만, 화면에 표시 NOT IN 요소, 나는를 받고있을 때 메시지 :

Failed: element not visible: Element is not currently visible and may not be manipulated 

저에게 도움이되는 팁이 있습니까?

+1

요소가 보이는지 여부를 확인해야하는 것처럼 들립니다. – Barmar

+1

관련 : https://stackoverflow.com/questions/36544589/element-is-not-currently-visible-and-so-may-not-be-interacted-with-when-clicking – Barmar

답변

1

요소가 표시되는지 확인해야합니다. 요소가 존재하지만 (DOM의 일부) 숨겨져 있습니다. 요소가 있는지 먼저 확인하지 않고 요소가 표시되는지 여부를 확인할 수 없습니다. 요소가없는 경우 isDisplayed() 메서드에서 오류가 발생합니다.

this.checkDropdownPresent = function (dropdownLocator, chooseOption) { 
    dropdownLocator.isPresent().then(function (present) { 
     if (present) { 
      dropdownLocator.isDisplayed().then(function (displayed) { 
       if (displayed) { 
        let select = dropdownLocator; 
        select.element(by.cssContainingText('option', chooseOption)).click(); 
       } 
      }); 
     } 
    }); 
}; 
0

답장을 보내 주셔서 감사합니다.

isPresent()isDisplayed()으로 변경하여 문제를 해결했습니다. 지금 제 코드를 확인하십시오 :

this.checkDropdownPresent = function (dropdownLocator, chooseOption) { 
    dropdownLocator.isDisplayed().then(function(element) { 
     if (element) { 
      let select = dropdownLocator; 
      select.element(by.cssContainingText('option', chooseOption)).click(); 
     } 
    }); 
}; 
+1

finspin의 답변을 다시 읽어야합니다. 조건부 클릭을 사용하려는 경우 고려하면 조금 더 좋습니다. "isDisplayed()'메서드는 요소가 없으면 오류를 throw합니다."... 가능한 오류를 방지하려면 시나리오에서 두 가지를 모두 확인하는 것이 좋습니다. 나는 그의 대답을 정확하다고 표시 할 것이다. – Gunderson