java工作复习——单选下拉列表——检查单选列表的选项文字是否符合期望

 

 

 

 

 

 

 

 

 

 

 

 

package jkcs;

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.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class jdcs 
{
    
    public static void main(String[] args) throws InterruptedException 
    {
        System.setProperty("webdriver.chrome.bin","‪C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");    //设置安装路径,防止系统找不到
        
        WebDriver driver = new FirefoxDriver();        //初始化FireFox浏览器实例,并打开浏览器

        driver.manage().window().maximize();         //最大化窗口  
        
        
        
        driver.get("http://www.baidu.com");    //打开一个网址,方法一
        
        Thread.sleep(8000);
        
        
        
        
        
        
        Actions action = new Actions(driver);
        
        
        action.moveToElement(driver.findElement(By.linkText("设置"))).perform();     //鼠标悬浮在 设置  元素上面
        
        driver.findElement(By.className("setpref")).click();      // 打开搜索设置
        
        
        Thread.sleep(8000);
        
        
        
       
        List<String> expect_options = Arrays.asList( new String[]{"每页显示10条","每页显示20条","每页显示50条"});
        
        
        
        
        
        Select dropList = new Select(driver.findElement(By.name("NR")));
        
        List<String> actual_option = new ArrayList<String>();
        
        for ( WebElement option:dropList.getOptions() )
            actual_option.add(option.getText());
        
        Assert.assertEquals(expect_options.toArray(),actual_option.toString());

        
        
        Thread.sleep(8000);
        

        driver.quit();
    }
}

 

posted @ 2020-04-21 16:41  小白龙白龙马  阅读(180)  评论(0编辑  收藏  举报