Selenium之下拉框的选择

package com.gloryroad.Demo;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class OperateDropList {
String url="http://127.0.0.1:8020/HTMLDemo/HTMLPDir/Temp02/selection.html";
public WebDriver driver;
@BeforeMethod
public void setUp(){
driver=new FirefoxDriver();
driver.get(url);

}
@Test
public void testSelect(){
Select dropList=new Select(driver.findElement(By.name("fruit")));
Assert.assertFalse(dropList.isMultiple());
Assert.assertEquals("桃子", dropList.getFirstSelectedOption().getText());
dropList.selectByIndex(3);
Assert.assertEquals("泥猴桃", dropList.getFirstSelectedOption().getText());
dropList.selectByValue("shanzha");
Assert.assertEquals("山楂", dropList.getFirstSelectedOption().getText());
dropList.selectByVisibleText("西瓜");
Assert.assertEquals("西瓜", dropList.getFirstSelectedOption().getText());

}

@AfterMethod
public void tearDown(){
driver.close();
}



}

你可能感兴趣的:(Java编程,测试经验总结)