zoukankan      html  css  js  c++  java
  • Select对象__下拉框对象__select__获取随机下标

    一、代码如下

    package www.gui.v2;
    
    import java.awt.AWTException;
    import java.awt.List;
    import java.awt.Robot;
    import java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;
    import java.util.Random;
    import java.util.concurrent.TimeUnit;
    
    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 Xialakuang {
    	WebDriver driver= null;
    	Actions actions= null;
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Xialakuang gx= new Xialakuang();
    		gx.init();
    
    	}
    	
    	private void init() {
    		// TODO Auto-generated method stub
    		// TODO Auto-generated method stub
    		// System.setProperty("webdriver.firefox.bin", "D:\Mozilla
    		// Firefox\firefox.exe");
    		System.setProperty("webdriver.firefox.bin", "D:\FireFox__37\firefox.exe");
    
    		this.driver = new FirefoxDriver();// 启动火狐浏览器
    
    		this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);// 元素等待时间
    		this.driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);// 页面加载时间
    		this.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);// ajax请求
    		this.driver.manage().window().maximize();
    		// this.driver.get("https://www.baidu.com/");// 在浏览器中打开该网址
    		actions = new Actions(driver);
    		
    		this.driver.get("http://localhost/Agileone/");
    		this.driver.findElement(By.id("username")).sendKeys("admin");
    		this.driver.findElement(By.id("password")).sendKeys("admin");
    		this.driver.findElement(By.id("login")).click();
    		this.driver.findElement(By.partialLinkText("需求提案")).click();
    		
    		WebElement select= this.driver.findElement(By.id("type"));
    		Select selects= new Select(select);
    		//selects.selectByValue("Nothing");
    		//selects.selectByIndex(0);
    		java.util.List<WebElement> lists= selects.getOptions();
    		int count= lists.size();
    		int randomIndex= new Random().nextInt(count);//0<= ? < count
    		int actuallRandomIndex= randomIndex + 1;
    		
    		selects.selectByIndex(actuallRandomIndex);
    	}
    	
    	
    
    }
    
  • 相关阅读:
    C# 全局变量
    [C#]续:利用键代码自动转换生成字母键或其它键信息
    [WPF](小结2)DataGrid嵌套DataGrid(也叫主从表)
    [C#]winform窗口托盘
    C# arrayList动态添加对象元素,并取出对象元素的方法
    [WPF](小结3)DataGridInTreeView树嵌表
    [WPF](小结4)TreeView的数据分层模板
    [WPF](小结1)ListBox嵌套ListBox
    [C#]利用键代码自动转换生成字母键或其它键信息
    [C#]使用API 获取设置系统热键和快捷键
  • 原文地址:https://www.cnblogs.com/wujianbo123/p/7667846.html
Copyright © 2011-2022 走看看