0
点赞
收藏
分享

微信扫一扫

Selenium之下拉框内容的对比示例

辰鑫chenxin 2022-08-02 阅读 67

package com.gloryroad.Demo;



import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;



import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

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 CheckDropList {

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


}



@AfterMethod

public void tearDown(){

driver.close();

}

@Test

public void checkDropList(){

List<String> exception_string=Arrays.asList(new String[]{"桃子","西瓜","橘子","泥猴桃","山楂"});

List<String> actual_exception=new ArrayList<String>();

Select dropList=new Select(driver.findElement(By.name("fruit")));

List<WebElement> allOptions = dropList.getOptions();

for (WebElement option : allOptions) {

actual_exception.add(option.getText());


}

Assert.assertEquals(actual_exception.toArray(), exception_string.toArray());




}

}

举报

相关推荐

0 条评论