2014-04-23 2 views
0

HTML 내용 : 목록 상자에서 선택한 값을 검색하는 방법은 무엇입니까?

<select id="modalNewUser-body-information-timeZone" class="span12 ng-valid ng-dirty" ng-options="timezone for timezone in timezoneList" ng-model="newUser().timeZone" uid="timeZone" name="timezone"> 
    <option selected="" value="">-- Select One --</option> 
    <option value="0">AST</option> 
    <option value="1">EST</option> 
    <option value="2">CST</option> 
    <option value="3">MST</option> 
    <option value="4">PST</option> 
    <option value="5">YST</option> 
    <option value="6">HST</option> 
</select> 

가 나는 내가 그것을 검색 할 수있는 방법 목록 상자에서 'EST'를 선택했다고 가정? getFirstSelectedOption()을 사용하여 검색 할 수 없습니다. getText()

select select = new select (driver.findElement (by modidNewUser-body-information-timeZone "))))); select.selectByVisibleText ("EST"); String timeZone = select.getFirstSelectedOption(). getText();

답변

1

실제로 '선택'태그가있을 때만 선택 요소를 사용할 수 있다는 것을 알고 있습니다. 종종 드롭 다운 상자처럼 보이는 것은 실제로 Select 요소처럼 작동하지 않습니다. 당신이 이런 식으로 텍스트를 얻기 위해 노력하면 어떻게 (나는 믿는다, 나는 여기에 C# .NET을 해요,하지만 자바는 단지이 다른 대문자가) :

string timeZone = driver.FindElement(By.XPath("//option[@value = '1']")).Text; 

기대 수익 : "EST"

0

당신이 할 수있는 이 시도 :

$("#modalNewUser-body-information-timeZone option:selected").text(); 
0

코드는 나를 위해 잘 작동에 의해 제공합니다.

셀렌 버전을 업데이트하고 다시 시도해주십시오.

Select select = new Select(abhiDriver.findElement(By.id("modalNewUser-body-information-timeZone"))); 
select.selectByVisibleText("EST"); 
String timeZone = select.getFirstSelectedOption().getText(); 
System.out.println(timeZone); 
: 다음

는 테스트 코드

관련 문제