selenium java传感器修改

用selenium编写自动化脚本部署完传感器,还需要修改其中传感器类型


package gcpi;


import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class ModifyGcpi2 {
	public static void main(String[] args) throws InterruptedException {
		WebDriver driver = new FirefoxDriver();
		driver.get("http://192.168.28.52:8100/GCPI/0-webapp/html/factory_config.html#/sensor");
		
		// login
		driver.findElement(By.cssSelector(".container-section-inputOne.container-section-input."
				+ "ng-pristine.ng-untouched.ng-valid.ng-valid-maxlength")).clear();
		driver.findElement(By.cssSelector(".container-section-inputOne.container-section-input."
				+ "ng-pristine.ng-untouched.ng-valid.ng-valid-maxlength")).sendKeys("aa");
		driver.findElement(By.cssSelector(".container-section-inputTwo.container-section-input."
				+ "ng-pristine.ng-untouched.ng-valid")).clear();
		driver.findElement(By.cssSelector(".container-section-inputTwo.container-section-input."
				+ "ng-pristine.ng-untouched.ng-valid")).sendKeys("123456");
		driver.findElement(By.cssSelector(".container-section-inputThree")).click();
		
		Thread.sleep(3000);
		
		// 传感器配置
		driver.findElement(By.xpath(".//*[@id='sensorId']")).click();
		Thread.sleep(2000);           
		
		driver.manage().window().maximize();
		Thread.sleep(2000);
		
		// 鼠标滚动到页面最底部
		JavascriptExecutor driver_js= (JavascriptExecutor) driver;
		driver_js.executeScript("window.scrollTo(0,document.body.scrollHeight)");
		
		// 设置每页查询8条
		//Thread.sleep(3000);
		driver.findElement(By.xpath("html/body/div[5]/div/div/div/div/div[2]/div/div[2]/span[7]/input")).sendKeys("8");
		//driver.findElement(By.cssSelector("#checkfenye_mySelect2")).sendKeys("8");
		Thread.sleep(5000);
		
		// 下一页
		//driver.findElement(By.xpath(".//*[@id='fixed_left_id']/div/div/div/div/div[2]/div/div[2]/span[4]")).click();
		//Thread.sleep(3000);
		
		// 设置从第3页开始
		driver.findElement(By.xpath("html/body/div[5]/div/div/div/div/div[2]/div/div[2]/span[6]/input")).sendKeys("3");
		Thread.sleep(5000);
		int j = 133;
		while(true){
			
			for(int i=1; i<=5; i++){
				String xpathString = ".//*[@id='dataTables-example']/tbody/tr[" + i + "]/td[19]/a/img";
				System.out.println(xpathString);
				Thread.sleep(4000);
				driver.findElement(By.xpath(xpathString)).click();
				//Thread.sleep(2000);
				WebElement input = driver.findElement(By.xpath("html/body/div[5]/div/common-sensoralter/div[1]/div/div/div[2]/div[2]/input"));
				Thread.sleep(2000);
				//WebElement input = driver.findElement(By.cssSelector(".form-control.ng-pristine.ng-untouched.ng-valid"));
				//WebElement input = driver.findElement(By.className("form-control ng-pristine ng-untouched ng-valid"));
				//Thread.sleep(2000);
				JavascriptExecutor js = (JavascriptExecutor) driver; 
				String value = (String)js.executeScript("return arguments[0].value;",input);  
				
				System.out.println(value);
				
				Select userSelect2=new Select(driver.findElement(By.xpath(".//*[@id='alterList_device_type_id']"))); 
				Thread.sleep(2000);
				
				if(value.equals("冷风机运行")){
					//Select userSelect2=new Select(driver.findElement(By.xpath(".//*[@id='alterList_device_type_id']")));  
					userSelect2.selectByVisibleText("冷风机运行信号");
					System.out.println("=======冷风机运行=======");
				}
				else if (value.equals("新风机运行")) {
					userSelect2.selectByVisibleText("新风机运行信号");
					System.out.println("=======新风机运行=======");
				}
				else if (value.equals("加湿器1运行")) {
					userSelect2.selectByVisibleText("加湿器运行信号");
					System.out.println("=======加湿器1运行=======");
				}
				else if (value.equals("加湿器2运行")) {
					userSelect2.selectByVisibleText("加湿器运行信号");
					System.out.println("=======加湿器2运行=======");
				}
				else if (value.equals("机组状态")) {
					userSelect2.selectByVisibleText("机组状态");
					System.out.println("=======机组状态=======");
				}
				else if (value.equals("室内温度")) {
					userSelect2.selectByVisibleText("环境温度");
					System.out.println("=======环境温度=======");
				}
				else if (value.equals("室内温度")) {
					userSelect2.selectByVisibleText("环境湿度");
					System.out.println("=======环境湿度=======");
				}
				else if (value.equals("室内CO2")) {
					userSelect2.selectByVisibleText("环境CO2");
					System.out.println("=======环境CO2=======");
				}
				else {
					System.out.println("========error=====" + i + "=============");
				}
				if(value.equals("aaa")){
					//Select userSelect2=new Select(driver.findElement(By.xpath(".//*[@id='alterList_device_type_id']")));  
					userSelect2.selectByVisibleText("风机故障报警");
				}
				
				if(value.equals("bbb")){
					//Select userSelect2=new Select(driver.findElement(By.xpath(".//*[@id='alterList_device_type_id']")));  
					userSelect2.selectByVisibleText("风扇电机状态");
				}
				
				//点击确认修改
				Thread.sleep(3000);
				driver.findElement(By.xpath("html/body/div[5]/div/common-sensoralter/div[1]/div/div/div[9]/span[1]")).click();
				Thread.sleep(3000);       
				driver.findElement(By.xpath("html/body/common-showalerttxtbox/div/div/div/ul[2]/li/span")).click();
	
			}
			// 下一页
			driver.findElement(By.xpath("html/body/div[5]/div/div/div/div/div[2]/div/div[2]/span[4]")).click();
			Thread.sleep(3000);
			System.out.println("=====第" + j + "页====");
			j++;
		}
	}

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章