【cl】selenium实例一:打开百度,获取第四个标题
/*创建类的时候是TestNG Class*/
package Selenium_lassen;
import static org.junit.Assert.*;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Case4 {
WebDriver driver;
@Test
public void test() {
System.setProperty("webdriver.firefox.bin", "D:\\ruanjian\\Firefox\\azml\\firefox.exe");
driver=new FirefoxDriver();//打开Firefox; open firefox
driver.get("http://www.baidu.com");//打开百度open the url
driver.findElement(By.id("kw")).sendKeys("GitHub");//输入搜索关键字“GitHub";input search keyword
driver.findElement(By.id("su")).click();//点击搜索按钮click the search button
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);//等页面加载,10秒内不加载成功即报超时。waiting for 10 seconds
String aResult=driver.findElement(By.xpath(".//*[@id='4']/h3/a")).getText();//取第四条搜索结果的标题。 get the text of 4th search result
System.out.println("标题是:"+aResult);
assert aResult.contains("GitHub");//做断言 assertion
driver.findElement(By.xpath(".//*[@id='4']/h3/a")).click();//打开第四个搜索结果。Open the 4th search result on baidu
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);//等页面加载,10秒内不加载成功即报超时。waiting for 10 seconds
//获取所有窗口的handle,然后逐个切换,直到切换到最新窗口 switch to the new window
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
String aTitle=driver.getTitle();//取新窗口的title
System.out.println("current widnow title is:"+aTitle);//打出来看看
assert aTitle.contains("GitHub");//断言
}
}
【cl】selenium实例一:打开百度,获取第四个标题的更多相关文章
- python+selenium调用chrome打开网址获取内容
目录 1,安装selenium和配置chromedriver 2,调用chromedriver打开网页获取网页内容 3,模拟登陆百度云 附录(webdriver版本兼容列表) 通过selenium库, ...
- python selenium启动浏览器打开百度搜索
python selenium打开百度搜索 #!usr/bin/python from selenium import webdriver import time browser = webdrive ...
- Selenium2学习-022-WebUI自动化实战实例-020-JavaScript 在 Selenium 自动化中的应用实例之二(获取浏览器显示区域大小)
前几篇文章中简略概述了,如何获取.设置浏览器窗口大小,那么我们该如何获取浏览器显示区域的大小呢?此文讲对此进行简略概述,敬请各位小主参阅.若有不足之处,敬请各位大神指正,不胜感激! 获取浏览器显示区域 ...
- selenium基础-打开百度进行搜索
1. 安装Python 2. 安装selenium 3. 下载谷歌驱动ChromeDriver,放到Python的Scripts目录下 4. 编写代码,如下 # coding: utf-8 from ...
- selenium实例:unittest框架+PO开发模式
这是<selenium2+python学习总结>的升级版. 1. 项目结构 2. 项目代码 1) globalparameter.py # ...
- Python+Selenium基础篇-打开和关闭火狐浏览器
本节介绍如何初始化一个webdriver实例对象driver,然后打开和关闭firefox浏览器.要用selenium打开fiefox浏览器.首先需要去下载一个driver插件geckodriver. ...
- Selenium2学习-009-WebUI自动化实战实例-007-Selenium 8种元素定位实战实例源代码(百度首页搜索录入框及登录链接)
此 文主要讲述用 Java 编写 Selenium 自动化测试脚本编写过程中,通过 ID.name.xpath.cssSelector.linkText.className.partialLinkTe ...
- PPTP VPN不能打开百度
问题: 在阿里云上设置PPTP VPN,电脑能正常连接,能打开京东 淘宝 QQ等没有问题,但是不能打开百度 糯米等网站.开始怀疑是代理设置问题,后面确认未设置独立规则. 1.从应用层看排除特殊规则设 ...
- Swift轻松入门——基本语法介绍和详细地Demo讲解(利用WebView打开百度、新浪等网页)
转载请务必注明出处(all copyright reserved by iOSGeek) 本文主要分为两个部分,第一部分介绍Swift的基本语法,第二部分讲解一个利用WebView来打开百度.sina ...
随机推荐
- SpringCloud(二) 服务注册与发现Eureka
1.eureka是干什么的? 上篇说了,微服务之间需要互相之间通信,那么通信就需要各种网络信息,我们可以通过使用硬编码的方式来进行通信,但是这种方式显然不合适,不可能说一个微服务的地址发生变动,那么整 ...
- 剑指offer笔记
1.在定义类的赋值描述符成员函数时,有以下几点要注意: 1)判断是否是自己赋值给自己 2)返回值是const类的引用(为了连续赋值) 3)参数是const类的引用 4)如果数据成员中有指针,注意要深拷 ...
- Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have A
Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you ...
- 题解报告:hdu 4764 Stone(巴什博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4764 Problem Description Tang and Jiang are good frie ...
- Android 判断app是否安装
1. private boolean isAppInstalled(Context context, String uri) { PackageManager pm = context.getPack ...
- Android 解决小米手机Android Studio安装app 报错的问题It is possible that this issue is resolved by uninstalling an existi
Android Studio升级到2.3版本之后,小米手机MIUI8不能运行Android Studio程序,报如下错误: Installation failed with message Faile ...
- Unity引擎GUI之Input Field
InputField 文本输入组件,本文练习InputField的属性及事件 一.属性 1 Interactable: 是否禁用 Transition:过渡方式 Normal Color 正常的未有任 ...
- 【Linux】tmpfs简介及增加方式
一. 什么是tmpfs? tmpfs是一种基于内存的文件系统,它和虚拟磁盘ramdisk比较类似,但不完全相同,和ramdisk一样,tmpfs可以使用RAM,但它也可以使用swap分区来存储.而且传 ...
- 【Oracle】客户端监听配置
首先找到oracle软件安装的目录,找到\product\11.2.0\client_1\network\admin,打开tnsnames.ora文件: 粘贴一下内容: LISTENER= (DESC ...
- 【Oracle】进入sqlplus 删除键backspace时出现^H
当oracle进入sqlplus后,输入命令时候出现错误,我们按平时的习惯使用backspace键删除错误信息,此时会出现^H 解决办法:进入sqlplus之前,使用stty erase '^H'命令 ...