나는이 페이지에 선택이 있습니다셀레늄 2 + WebDriver + .NET : 선택 인 경우의 옵션을 선택의 텍스트를 검색 할 수 없습니다 "디스플레이 : 없음;"
<select multiple="" class="recipientsList" name="Recipients[]" id="To" style="display: none;">
<option value="User-6" class="">Coordinator, Test</option>
<option value="Course-4" class="">New Course 1</option>
<option value="UserType-6" class="">Coordinators</option>
<option value="UserTypeInCourse-4-6" class="">New Course 1 Coordinator</option>
</select>
그리고이 테스트를 실행 해요 :
public IWebDriver WebDriver
{
get
{
// gets the current WebDriver instance, set up elsewhere at the beginning
// of the fixture
return ScenarioContext.Current.WebDriver();
}
}
public void SelectTest()
{
// code to navigate to proper page
var options = WebDriver.FindElements(By.CssSelector("select.recipientsList option"));
Assert.That(options, Is.Not.Empty, "No options found.");
Assert.That(!options.Any(option => string.IsNullOrEmpty(option.Text)), "Some or all options have blank text.");
// Actual useful assert
}
두 번째 써트 options
컬렉션의 모든 요소가 같은 빈 문자열이 있기 때문에 실패입니다 그들의 Text 객체. display:none;
스타일을 추가 한 페이지에서 자바 스크립트를 삭제하면 작동합니다. 이 선택은 숨길 필요가 있기 때문에 영구적 인 해결책은 아닙니다. FCBKcomplete으로 확장됩니다.
내가 .NET에서 셀레늄이/WebDriver와 숨겨진 옵션을 선택의 텍스트를 어떻게합니까?
이는 의미가 있습니다. 우리는 FCBKComplete가 렌더링하는 자동 완성 드롭 다운에서 정보를 찾는 방법을 알아 내야 할 것입니다. 감사! – adamjford
또한 표시 속성을 변경하고 텍스트를 가져올 일부 JavaScript를 실행할 수 있습니다. 스크립트를 실행하기 위해 IWebDriver를 IJavascriptExecutor로 캐스팅하여 수행 할 수 있습니다 (인터페이스 이름에 실수가있을 수 있으므로 Java를 사용하고 있습니다). –