1

Java셀레늄을 사용하여 테스트를 작성합니다. 드롭 다운 메뉴에서 뭔가를 선택해야합니다. 이건 내 코드입니다 : 파이어 폭스 크롬에 있지만 에서 작동firefox의 dropdpwn 메뉴에서 선택할 수 없습니다

Select s= new Select(driver.findElement(By.xpath("blabla"))); 
s.selectByVisibleText("theName"); 

나는이 오류를 얻을 :

org.openqa.selenium.ElementNotVisibleException: 
Element is not currently visible and so may not be interacted with 

나는 다른 방법으로 드롭 다운 메뉴에서 선택 처리하는 방법을 알고를, 하지만 Select 개체를 사용해야합니다.

+2

XPath가 FF에서 유효하다는 것을 확인 했습니까? 관련 HTML 없이는 도움이 어렵습니다. – JeffC

+0

그래서 'WebDriverWait'을 사용하여 표시 될 때까지 기다렸습니까 ?? –

+0

xpath 대신 CSS 선택기를 사용해보십시오. Coz xpath는 모든 브라우저에서 다를 수 있습니다. –

답변

0

사용 유창 대기가 요소를 기다리는, 크롬은 빠른 :

public static void waitUntilElementIsVisible(WebElement element, WebDriver driver) 
{   
    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver); 
    wait.pollingEvery(250, TimeUnit.MILLISECONDS); 
    wait.withTimeout(2, TimeUnit.MINUTES); 
    wait.ignoring(ElementNotVisibleException.class); //make sure that this exception is ignored 
    Function<WebDriver, WebElement> function = new Function<WebDriver, WebElement>() 
      { 
       public WebElement apply(WebDriver driver) { 
        System.out.println("Checking for the element!!");      
        if(element.isDisplayed() != true) 
        { 
         System.out.println("Target element is not visible"); 
        } 
        return element; 
       } 
      }; 

    wait.until(function); 
} 

그런 다음 당신은 그것을 호출 할 수

WebElement el = driver.findElement(By.xpath("blabla")); 
waitUntilElementIsVisible(el, driver); 
0

당신은 요소의 가시성과 같은 대기하는 WebDriverWait 클래스를 사용할 수 있습니다 이 :

WebDriverWait wait = new WebDriverWait(driver, customTime); 
WebDriver driver = new FirefoxDriver(); 

Select s = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("blabla"))); 
s.selectByVisibleText("theName"); 
+0

이 이미 그것을 수행했으나 작동하지 않았습니다. –