【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 ...
随机推荐
- sublime 的快捷键大全
Sublime Text 3 快捷键精华版 Ctrl+Shift+P:打开命令面板 Ctrl+P:搜索项目中的文件 Ctrl+G:跳转到第几行 Ctrl+W:关闭当前打开文件 Ctrl+Shift+W ...
- .net core2.0 中使用aspectcore实现aop
一.新建一个web application项目 1.1.添加AspectCore.Extensions.DependencyInjection引用 二.实现AbstractInterceptorAtt ...
- SQLServer2008 关于while循环
有这样一个表tbl id code name 11 a aa/bb/cc 22 b ee/rr/tt 需要将name段根据‘/’拆分开来,变成新的数据行 即: id c ...
- poj3009 Curling 2.0 深搜
PS:以前看到题目这么长就没写下去了.今天做了半天,没做出来.准备看题解,打开了网站都忍住了,最后还是靠自己做出来的.算是一点进步吧. 分析: 题目的意思没明白或者理解有偏差都没办法做题.看样例3和样 ...
- 对学Oracle数据库初学者的开场篇
前言:因为项目原因,近期开始学习Oracle数据库.Oracle是目前最流行的数据库之一,功能强大,性能卓越,相对的学习的难度还是不小.我打算将自己的学习过程记录下来,做个积累,方便自己和其他的学习者 ...
- Interrupt中断线程
package com.wistron.swpc.ecs.util; public class WrongWayStopThread extends Thread{ public static voi ...
- 图像连通域检测的2路算法Code
本文算法描述参考链接:http://blog.csdn.net/icvpr/article/details/10259577 两遍扫描法: (1)第一次扫描: 访问当前像素B(x,y),如果B(x,y ...
- 教材配套PPT初稿
1-10章初稿,基本完整.有些粗糙,后面可能会稍作调整. 附更新情况如下: 1.增加了第10章内容: 2.第5章增加了一些内容: 3.第3章内容部分更新: 4.增加了第8-9章内容. 订正:更新了第8 ...
- (转) OpenLayers3基础教程——OL3 介绍control
http://blog.csdn.net/gisshixisheng/article/details/46761535 概述: 本文讲述的是Ol3中的control的介绍和应用. OL2和OL3 co ...
- Java+selenium+Firefox/ IE/ Chrome主流浏览器自动化环境搭建
一.java+selenium+firefox 1.环境准备:JDK1.8 2.安装firefox浏览器v59 3.下载驱动:https://github.com/mozilla/geckodrive ...