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();
}
}
Selenium入门练习(一)的更多相关文章
- 自动化测试Java一:Selenium入门
From: https://blog.csdn.net/u013258415/article/details/77750214 Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介 ...
- Selenium自动化测试Python一:Selenium入门
Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介绍Selenium的入门知识以及Selenium的前置知识. 自动化测试的基础 在Selenium的课程以前,我们先回顾一下软件 ...
- Selenium 入门到精通系列:六
Selenium 入门到精通系列 PS:Checkbox方法 例子 HTML: <html> <head> <title>测试页面</title> &l ...
- Selenium 入门到精通系列:五
Selenium 入门到精通系列 PS:显式等待.隐式等待.强制等待方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019 ...
- Selenium 入门到精通系列:四
Selenium 入门到精通系列 PS:鼠标右键.鼠标悬停.键盘操作方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019 ...
- Selenium 入门到精通系列:三
Selenium 入门到精通系列 PS:Driver_Element 常用方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2 ...
- Selenium 入门到精通系列:二
Selenium 入门到精通系列 PS:用户登录 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019-04-23 16:12 ...
- Selenium 入门到精通系列:一
Selenium 入门到精通系列 PS:控制浏览器窗口大小.前进.后退.刷新 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 20 ...
- Selenium入门6 操作元素,获取元素属性
取元素的text,属性get_attribute,标签名tag_name 操作元素:send_keys输入,click点击,submit提交,clear清除输入 状态判断:is_display,is_ ...
- python3+selenium入门01-环境搭建
作为一个测试,在最近两年应该有明显的感觉.那就是工作变的难找,要求变的高了,自动化测试,性能测试等.没有自动化测试能力,只会点点点工作难找不说,工资也不高.所以还是要学习一些技术.首先要学习一门编程语 ...
随机推荐
- 如何设计Spring读取某种文件的逻辑顺序
1. 判断系统属性System.getProperty("apdb.config.path", "");,有的话,优先使用.(系统属性可以在命令行中以 -D&l ...
- android 读取联系人
设置读取权限 <uses-permission android:name="android.permission.READ_CONTACTS" /> <u ...
- Java基础知识陷阱(七)
本文发表于本人博客. 上次说了下HashSet和HashMap之间的关系,其中HashMap这个内部有这么一句: static final float DEFAULT_LOAD_FACTOR = 0. ...
- Python3 安装第三方包
打开cmd(切记是cmd,不是Python3.6那个敲代码环境)输入 pip3 install numpy 即可(安装numpy包)
- [笔记] Python实现全排列算法
所谓全排列,就是给定数组,将所有的可能排列组合都枚举出来,n个元素共有n!种排列组合. 举例,对于['1', '2', '3'],全排列结果为:123,132,213,231,312,321,共有3! ...
- 运输层协议--TCP及UDP协议
TCP及UDP协议 按照网络的五层分级结构来看,TCP及UDP位于运输层,故TCP及UDP是运输层协议.TCP协议--传输控制协议UDP协议--用户数据报协议 多路复用及多路分解 图多路复用及多路分解 ...
- SpringCloud Config Server中{application}等占位符使用场景设置默认拉去分支
Spring Cloud Config服务器支持一个Git仓库URL,其中包含{application}和{profile}(以及{label})的占位符. 1.各个占位符所代表的含义 applica ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) D. Volatile Kite
地址:http://codeforces.com/contest/801/problem/D 题目: D. Volatile Kite time limit per test 2 seconds me ...
- JAVA中hashmap的分析
从http://blog.csdn.net/luanlouis/article/details/41576373?utm_source=tuicool&utm_medium=referral学 ...
- handle 和module
<httpHandlers> <add verb="*" path="*" type="ClassLibrary831.TestHa ...