zoukankan      html  css  js  c++  java
  • Selenium入门练习(二)

    自动登录博客园并且退出登录

    package TestNG;

    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeTest;
    import org.openqa.selenium.Alert;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.annotations.AfterTest;

    public class SecondTest {
    @Test
    public void f() throws InterruptedException {
    // System.out.println("hello World!!!");
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.baidu.com");
    driver.manage().window().maximize();

    driver.findElement(By.id("kw")).sendKeys("博客园");
    driver.findElement(By.id("su")).click();
    Thread.sleep(1000);
    driver.findElement(By.xpath("//div[@id='1']/h3/a")).click();

    String thisHandleId = driver.getWindowHandle();

    for(String TempHandleId : driver.getWindowHandles())
    {
    if(!TempHandleId.equals(thisHandleId))
    {
    driver.switchTo().window(TempHandleId);
    }
    }

    driver.findElement(By.linkText("登录")).click();
    Thread.sleep(1000);

    driver.findElement(By.id("input1")).sendKeys("nieliangcai");
    driver.findElement(By.id("input2")).sendKeys("nlc@13661501664");
    Thread.sleep(1000);

    driver.findElement(By.id("signin")).click();
    Thread.sleep(1000);

    driver.findElement(By.linkText("退出")).click();
    Thread.sleep(1000);

    Alert Dialog = driver.switchTo().alert();
    Dialog.accept();
    System.out.println(driver.getTitle());

    }
    @BeforeTest
    public void beforeTest() {
    System.out.println("@BeforeTest");
    }

    @AfterTest
    public void afterTest() {
    System.out.println("@AfterTest");
    }
    }

  • 相关阅读:
    header
    panel----单个基础版
    vue-demo
    js不同类型变量比较
    reset.css
    关于各个浏览器的兼容问题
    git
    AMD与CMD区别
    喜欢前端的看过来哦
    js中数组去重的几种方法
  • 原文地址:https://www.cnblogs.com/nieliangcai/p/7156268.html
Copyright © 2011-2022 走看看