나는 노력 이 일을하고 태그 이름을 선택하면 완벽하게 작동하지만 사용할 때 Select select = new Select();
태그 이름 div
, 또는 무엇인가, 그것은 다음과 같은 오류와 작업 및 프롬프트 나에 실패합니다 org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "div"
.
<div stop-propagation="click" class="custom-select-search">
<input class="undefined ng-pristine ng-valid ng-touched" type="text" autocomplete="off" ng-model="searchTerm">
</div>
<ul role="menu">
<li role="presentation" class="ng-scope">
<a role="menuitem" tabindex="-1" href=""ng-click="select(s)" class="ng-binding">166</a>
</li>
<li role="presentation" class="ng-scope">
<a role="menuitem" tabindex="-1" href=""ng-click="select(s)" class="ng-binding">164</a>
</li>
<li role="presentation" class="ng-scope">
<a role="menuitem" tabindex="-1" href=""ng-click="select(s)" class="ng-binding">165</a>
</li>
<li role="presentation" class="ng-scope">
<a role="menuitem" tabindex="-1" href=""ng-click="select(s)" class="ng-binding">166</a>
</li>
</ul>
이것은 내 코드입니다.
WebElement elements = driver.findElement(serial);
Select ComboBoxValues = new Select(elements);
List <WebElement> weblist = ComboBoxValues.getOptions();
int iCnt = weblist.size();
Random num = new Random();
int iSelect = num.nextInt(iCnt);
ComboBoxValues.selectByIndex(iSelect);
System.out.println("Element Name 1 : " +elements.getAttribute("value"));
누구든지이 일을하라고 말할 수 있습니까?
사이트에 드롭 다운을 에뮬레이트하는 사용자 지정 UI가있는 것 같습니다. 즉, 상호 작용하려면 자체 코드를 구현해야합니다. 클래스를 생성하는 것이 좋습니다. MySiteSelector라고 부르겠습니다. 메뉴 목록을 열기 위해 클릭 할 위치를 아는 select () 메서드 (여기에있는 것처럼 보이지 않음)를 가진 다음 목록 항목을 검색합니다 (a css 선택기는 "ul [role = 'menu] li")가되어 원하는 대상과 일치하는 항목을 찾습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다