• 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");
    }
    }

  • 相关阅读:
    Redis常用配置说明
    Redis入门知识
    分布式理论基石CAP理论
    MySQL之视图
    MySQL之事务控制总结
    MySQL之标识列(自增长列)设置起始值与步长
    LeetCode 543. Diameter of Binary Tree(两节点最长路径)
    LeetCode 110. Balanced Binary Tree(平衡树)
    LeetCode 104. Maximum Depth of Binary Tree(求树的高度)
    LeetCode 328. Odd Even Linked List(链表元素按奇偶聚集)
  • 原文地址:https://www.cnblogs.com/nieliangcai/p/7156268.html
Copyright © 2020-2023  润新知