java+selenium在自动添加设备

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lanjingling_zz/article/details/82783842

脚本是基于某电信项目完成的
语言为Java
框架为selenium
经过测试可正常使用,分享脚本如下

package test;
 
import java.util.List;
 
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
 
public class addOneDevice {
	@Test
	public void test() throws InterruptedException {
		System.setProperty("webdriver.chrome.driver","D:/software/Tools/eclipse+selenium_tools/chromedriver.exe");
		WebDriver dr= new ChromeDriver();
		dr.manage().window().maximize();
                //此处是生产环境,以***代替
		dr.get("*****");
 
		//*[@id="container_login"]/div[1]/img
		WebElement loginUser = dr.findElement(By.xpath("//*[@id=\"username\"]"));
		loginUser.clear();
		loginUser.sendKeys("admin");
		WebElement login_pswd = dr.findElement(By.xpath("//*[@id=\"password\"]"));
		login_pswd.clear();
		login_pswd.sendKeys("iradar");
		WebElement login_enter = dr.findElement(By.xpath("//*[@id=\"enter\"]"));
		login_enter.click();
		Thread.sleep(2000);
                //此处环境是生产环境,以***代替
		dr.get("××××");
		Thread.sleep(3000);
		WebElement add_device = dr.findElement(By.cssSelector("a.tipso_style"));
		add_device.click();		
 
 
		WebElement hosts = dr.findElement(By.xpath("//*[@id=\"host\"]"));
		hosts.sendKeys("windows_1");
		WebElement hostsVisiblename = dr.findElement(By.xpath("//*[@id=\"visiblename\"]"));
		hostsVisiblename.sendKeys("windows_1_1");
		Select rightbar =new Select(dr.findElement(By.xpath("//*[@id=\"groups_right\"]")));
		rightbar.selectByValue("102");
		WebElement addbutton = dr.findElement(By.xpath("//*[@id=\"add\"]"));
		addbutton.click();
		WebElement hostIp = dr.findElement(By.xpath("//*[@id=\"hostInterfaceRow_1\"]/td[2]/input"));
		hostIp.clear();
		hostIp.sendKeys("192.168.202.218");
		WebElement hostInterface = dr.findElement(By.xpath("//*[@id=\"hostInterfaceRow_1\"]/td[5]/input"));
		hostInterface.clear();
		hostInterface.sendKeys("10050");
		WebElement templateButton = dr.findElement(By.xpath("//*[@id=\"tab_templateTab\"]"));
		templateButton.click();		
		WebElement chooseButton = dr.findElement(By.xpath("//*[@id=\"newTemplateTable\"]/tbody/tr[1]/td/div/input"));
		chooseButton.click();		
		dr.switchTo().frame("ifr_rda_popup");
		Thread.sleep(2000);
		List els = dr.findElements(By.xpath("//input[@type='checkbox']"));
		els.get(els.size()-7).click();
		dr.findElement(By.xpath("//*[@id=\"select\"]")).click();
		dr.switchTo().defaultContent();	
		dr.findElement(By.xpath("//*[@id=\"add_template\"]")).click();
		dr.findElement(By.xpath("//*[@id=\"save\"]")).click();
 
		Thread.sleep(3000);				
		dr.quit();
 
 
	}
}

猜你喜欢

转载自blog.csdn.net/lanjingling_zz/article/details/82783842
今日推荐