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();
}



}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值