verificar los valores desplegables usando WebDriver

I need to verify drop down values using WebDriver. i have expected values in a String array

String[] exp = {"--Title--","Mr","Mrs","Miss","Ms","Dr","Prof"};

I need to write a function that return all the values from drop down and i need to assert with expected values, Below is the code that i have written to print the values from drop down, but i need to assert those values with expected ones:-

WebElement dropdown = driver.findElement(By.id("ddlNights"));  
Select select = new Select(dropdown);  
List<WebElement> options = select.getOptions();  
for(WebElement we:options)  
{  
 System.out.println(we.getText());  
}  

Can anyone help me in writing a method that returns String array of drop down values, so that we can reuse the method for validating values in every drop down using
Assert.assertTrue(Arrays.equals(Expected,Actual))

¡¡¡Gracias por adelantado!!!

preguntado el 10 de marzo de 12 a las 05:03

1 Respuestas

Prueba esta

 String[] exp = {"--Title--","Mr","Mrs","Miss","Ms","Dr","Prof"};
 WebElement dropdown = driver.findElement(By.id("ddlNights"));  
 Select select = new Select(dropdown);  

 List<WebElement> options = select.getOptions();  
 for(WebElement we:options)  
 {  
  boolean match = false;
  for (int i=0; i<exp.length(); i++){
      if (we.getText().equals(exp[i]){
        match = true;
      }
    }
  Assert.assertTrue(match);
 }  

It should compare each element with every possibility in the expected Strings. The Match will be true only in "found" state. You can play around with the message with the Assert, because it can fail anytime. So you can do something like

Assert.assertTrue(match, we.getText());

Which should write you on which webElement it did not find any match - I am not 100% sure with that line - i dont have any IDE running to verify it.

respondido 12 mar '12, 15:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.