首页登录系统

只用于本人个人学习,如有问题,见谅


package
com.test; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class LoginHomePage { public static void main(String[] args) throws Exception { System.setProperty( "webdriver.chrome.driver", "C:/temp/chromedriver.exe");//定义找到谷歌浏览器驱动位置 WebDriver driver=new ChromeDriver(); //新建谷歌浏览器驱动 driver.get("http://10.139.8.38:7100/cam/xining/cm/#/index"); //打开此网站 driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);//隐式等待5秒让界面加载完成 // WebElement searchBox=driver.findElement(By.cssSelector("body > div > div > div > div.header.row > div.view-port > div.navPad.fr.col-xs-10 > div.loginPad > a"));//用csspath定位登录 WebElement searchBox=driver.findElement(By.partialLinkText("登录")); searchBox.click(); //点击提交 // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);//隐式等待10秒让界面加载完成 WebElement searchBox1=driver.findElement(By.cssSelector("body > div > div > div > div.header.row > div.view-port > div.navPad.fr.col-xs-10 > div.loginPad > div > ul > li:nth-child(1)"));//用csspath定位企业登录 searchBox1.click(); //点击提交 WebElement loginName=driver.findElement(By.id("username"));//id获取用户名位置 WebElement passWord=driver.findElement(By.id("password"));// id获取密码位置 loginName.sendKeys("13555983201");//赋值用户名 passWord.sendKeys("123456");//赋值密码 WebElement submit=driver.findElement(By.xpath("/html/body/div/div[1]/div/div[2]/div/div/div/div[2]/div/ul/li[4]/a"));//xpath定位登录按钮 submit.click();//点击提交 Thread.sleep(2000);//暂停一秒,线程等待不建议使用 //driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);//隐式等待10秒让界面加载完成 // WebElement send=driver.findElement(By.id("count-down"));//id获取验证码按钮位置 WebElement choice=driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div/div[2]/ul/li/ul[1]/li[3]")); choice.click(); WebElement lian=driver.findElement(By.linkText("联通")); lian.click(); WebElement send=(new WebDriverWait(driver,90)).until(ExpectedConditions.presenceOfElementLocated(By.id("count-down"))); System.out.println(send.isDisplayed());//是否可见 System.out.println(send.isEnabled());//是否可见 System.out.println(send.getText()); ((JavascriptExecutor)driver).executeScript("arguments[0].click();",send); WebElement code=driver.findElement(By.cssSelector("#corporationModal > div > div > div.modal-body > ul > li > ul:nth-child(2) > li:nth-child(2) > div:nth-child(1) > input"));//用csspath定位输入 验证码位置 code.sendKeys("666666");//赋值验证码 Thread.sleep(1000);//暂停一秒 WebElement queren=driver.findElement(By.id("sureLogin"));//id获取确认按钮位置 queren.click();//点击提交 Thread.sleep(1000);//暂停一秒 WebElement yingyong=driver.findElement(By.xpath("/html/body/div/div/div/div[1]/div[2]/div[2]/div[1]/span/a[2]")); //WebElement yingyong=driver.findElement(By.partialLinkText("管理")); System.out.println(yingyong.getCssValue("height"));//高度属性30px System.out.println(yingyong.getText());//元素的文本名字 System.out.println(yingyong.getTagName());//元素的tag name System.out.println(yingyong.getAttribute("value")); System.out.println(yingyong.getLocation());//元素的坐标信息 System.out.println(yingyong.getSize());//元素的长宽值 System.out.println(yingyong.isEnabled());//是否启用状态 System.out.println(yingyong.isDisplayed());//是否可见 yingyong.click(); buildber b=new buildber(); b.member(driver); try { Thread.sleep(5000); } catch (Exception e) { System.out.println("error");// TODO: handle exception } driver.quit(); } }
原文地址:https://www.cnblogs.com/snailvsstar/p/6178066.html