2013-12-19 3 views
0

나는 드롭 다운이있는 페이지가 있는데,이 요소에는 사용할 수있는 요소가 거의 없습니다. 드롭 다운 값을 반복하여 활성화 또는 비활성화되었는지 확인하고 싶습니다. Selenium/Webdriver가 가능합니까?Selenium/Webdriver를 사용하여 비활성화 된 옵션을 찾는 방법

<body> 
    <select id="s"> 
    <option value="0" selected="selected">0</option> 
    <option value="1" disabled>1</option> 
    <option value="2">2</option> 
    <option value="3">3</option> 
    <option value="4">4</option> 
    <option value="5">5</option> 
    </select> 
</body> 

답변

1

는 루비 기반 솔루션입니다 :

require 'selenium-webdriver' 

driver = Selenium::WebDriver.for :firefox 
driver.get "file:///C:/userdata/arupruby/test.html" 

# To search the drop-down element whose id is 's' 
elem = driver.find_element(:id,'s') 
sel = Selenium::WebDriver::Support::Select.new(elem) 

# To search if any element is present which has the disabled attribute. 
dis_elem = sel.options.find{|e| e.attribute('disabled') } 
dis_elem.text unless dis_elem.nil? # => "1" 
1

driver.get("\\test.html"); 
Select select = new Select(driver.findElement(By.id("s"))); 
System.out.println(select.getOptions().get(1).getAttribute("disabled")); #=> true 
+0

좋은! 나는 단지 같은 루비 솔루션을 줄 예정이었다. –

+0

이것은 루프를 실행하지 않고 첫번째'

2

가능한 솔루션을 내 자신의 질문에 대답 :

여기
WebElement temp = driver.findElement(By.id("s")); 
List<WebElement> opts = temp.findElements(By.xpath(".//option")); 
for (WebElement opt : opts){ 
    if (opt.isEnabled()){ 
     // do something 
    } 
} 
1
driver.findElement(By.xpath("//select[@id='s']/select[@disabled]")); 
관련 문제