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++;
		}
	}

}



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