2014-12-08 5 views
0

아래는 내 스크립트와 html입니다. 드롭 다운 메뉴를 클릭 할 수없고 목록에서 "열두 개"를 선택할 수 없습니다. xpath, name으로 시도했지만 아무것도 작동하지 않는 것 같습니다. 어떤 도움이라도 대단히 감사합니다. 감사!div에서 span 요소를 클릭하는 방법

내 스크립트를

WebElement temp = driver.finaElement(By.cssSelector("#s2id_campaignStatus > a.select2-choice > span")); 
temp.click(); 

HTML :

<table> 
    <tbody> 
     <tr> 
      <td> 
       <div> 
        <div class="select2-container select2-container-active" id="s2id_campaignStatus"> 
         <a href="javascript:void(0)" onclick="return false;" class="select2-choice" tabindex="-1">             
         <span>twelve</span> 
          <abbr class="select2-search-choice-close" style="display:none;"></abbr> 
          <div> 
           <b></b></div> 
           </a><input class="select2-focusser select2-offscreen" type="text"></div> 
           <select name="campaignStatus" id="campaignStatus" class="select2-offscreen" tabindex="-1"> 


           <option value="W" selected="selected">ABC</option> 

              <option value="L">one</option> 
              <option value="P">two</option> 
              <option value="O">three</option> 
              <option value="C">four</option> 
              <option value="R">five</option> 
              <option value="J">six</option> 
              <option value="X">seven</option> 
              <option value="S">eight</option> 
              <option value="A">nine</option> 
              <option value="D">ten</option> 
              <option value="T">twelve</option> 
           </select> 
          </div> 
         </td> 
        </tr> 
        <tr> 
         <td style="padding-left:12px;"> 
          <a href="#" onclick="showTemplate()"> 
           What is a Template? 
          </a> 
         </td> 
        </tr> 
       </tbody></table> 

내 테스트 코드 @Saifur :

new Select(driver.findElement(By.id("campaignStatus"))).selectByValue("T"); 

     By elementId = By.id("campaignStatus"); 
     WebDriverWait wait = new WebDriverWait(driver, 8); 
     wait.until(ExpectedConditions.presenceOfElementLocated(elementId)); 
     new Select(driver.findElement(elementId)).selectByValue("T"); 
+0

관련 태그 및 예외를 추가했는지 확인하십시오. – Saifur

답변

0
new Select(driver.findElement(By.id("campaignStatus"))).selectByVisibleText("twelve"); 

또한 Select 클래스를 사용하여 여러 옵션이 있습니다. 요소에 대한 this

new Select(driver.findElement(By.id("campaignStatus"))).selectByValue("T"); 

편집 추가 대기를 참조하십시오

By elementId = By.id("campaignStatus"); 
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds); 
wait.until(ExpectedConditions.presenceOfElementLocated(elementId); 
new Select(driver.findElement(elementId)).selectByValue("T"); 
+2

요소가 표시되어 있습니까? – Saifur

+0

보이지 않습니다. – familyGuy

+2

'select' 요소가 보이지 않습니까? 그렇다면 당신은 다른 행동으로 그것을 볼 수 있도록해야합니다. 표시되는 경우 일부 요소 대기 문제가 편집 된 코드를 사용하십시오 – Saifur

0

아래의 코드를 시도하십시오, 그것은 당신이

내가 수동 대기를 준 작동한다 준비 상태가 될 수 있습니다 드롭 다운 목록에서 ''을 선택하기 전과 후에 2 초.

선택 요소가 클릭 가능하게 될 때까지 대기 할 시간은입니다.

WebDriverWait wait = new WebDriverWait(driver, 8); 
WebElement Manages = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//select[@id='campaignStatus']"))); 
Select dropDownelement = new Select(Manages); 
Thread.sleep(2000); 
dropDownelement.selectByVisibleText("twelve"); 
Thread.sleep(2000); 
+0

이 오류가 발생합니다. org.openqa.selenium.TimeoutException : 요소를 클릭 할 때까지 대기하는 8 초 후 시간이 초과되었습니다. By.xpath : // select [@ id = 'campaignStatus'] @Rupesh Shinde – familyGuy

관련 문제