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

    自主学习---上海野生动物园之登录、订票、退票

    Create了一个TestNG可以查看执行结果:

    package FristTestNG;

    import java.sql.Driver;

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

    import com.thoughtworks.selenium.webdriven.commands.Click;

    public class ZooTest {
    @Test
    public void f() throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.shwzoo.com/");//输入URL进入网站
    driver.manage().window().maximize();//窗口最大化

    Thread.sleep(1000);

    driver.findElement(By.linkText("网上商城")).click();

    driver.findElement(By.linkText("登录")).click();//登录
    WebElement username = driver.findElement(By.id("txtUserName"));
    username.sendKeys("2397244682@qq.com");
    WebElement password = driver.findElement(By.id("txtPassword"));
    password.sendKeys("123456");
    driver.findElement(By.id("btnSubmit")).click();
    //成功登录

    driver.findElement(By.linkText("网上商城")).click();
    Thread.sleep(1000);

    driver.findElement(By.xpath("//img[contains(@src,'201704011017527881.jpg')]")).click();//购买成人票
    Thread.sleep(1000);

    //选票
    driver.findElement(By.xpath("//input[@class='add']")).click();
    driver.findElement(By.id("addtime")).sendKeys("2017-07-14");//日历怎么定位
    driver.findElement(By.linkText("立即购买")).click();
    driver.findElement(By.xpath("//div[@class='layui-layer-btn']/a")).click();
    Thread.sleep(1000);
    // Alert Dialog = driver.switchTo().alert();
    // Dialog.accept();

    //下单成功
    driver.findElement(By.name("remark")).sendKeys("先别买,我还要退货。。。谢谢");
    driver.findElement(By.id("btnSubmit")).click();
    Thread.sleep(1000);

    //更换窗口:当上一步骤执行后,打开了另外一个Windows时需要切换到改Windows窗口
    String thisHandleId = driver.getWindowHandle();
    for(String TempHanleId : driver.getWindowHandles())
    if(!TempHanleId.equals(thisHandleId))
    {
    driver.switchTo().window(TempHanleId);
    }
    //成功退票
    driver.findElement(By.xpath("//div[@class='wrap_1260']/ul/li[2]/a")).click();//B17061714522412143813
    Thread.sleep(1000);
    driver.findElement(By.xpath("//div[@class='main_content']/div[2]/div/a[3]")).click();
    Thread.sleep(1000);

    driver.findElement(By.xpath("//div[@class='layui-layer-btn']/a")).click();
    }
    }

  • 相关阅读:
    大象起舞:用PostgreSQL解海盗分金问题
    python 导入模块
    python socket 发送ESB报文
    python socket超时
    ISCC2018部分WriteUp
    查看SQL执行计划的方法及优劣
    jquery遮罩层
    IE9 JS不执行,打开F12就没问题了
    BigDecimal 01
    BigDecimal 01
  • 原文地址:https://www.cnblogs.com/nieliangcai/p/7156245.html
Copyright © 2011-2022 走看看