2016-08-30 2 views
0

select type의 드롭 다운 메뉴에서 데이터를 지우고 싶습니다만, select.clear()를 사용할 수 없습니다. "사용자가 편집 할 수 있어야합니다. 그것을 지우기 위해서 "이것은 합리적이다. 각자 필드를 지우는 데 어떤 명령을 사용해야하는지 알고 있습니까?Selenium에서 자바로 드롭 다운 메뉴를 지우는 법

+1

당신이 빈 옵션이있는 경우, 그 선택합니다. 오류 추측에서 일반 select 드롭 다운이 있습니다. – Grasshopper

답변

1

요소에 <select> 태그가있는 경우 상호 작용을 위해 선택 클래스를 사용할 수 있습니다.

// first, initialize the WebElement (using the appropriate selector type, this is just an example) 
WebElement element = driver.findElement(By.id("elementId")); 

// next, pass it to the Select object 
Select selectElement = new Select(element); 

// then, select an option from the element 
selectElement.selectByVisibleText("Option Text"); 

우리는 또한 인덱스 또는 값 (documentation)에 의해 선택할 수 있습니다

// finally, to clear your selection, try: 
selectElement.deselectAll(); 
관련 문제