Selenium Webdriver——去哪儿网输入实例
1.对出发地方和到达地方进行Xpath定位,这里采用了Xpath的text() 函数进行定位
用following::sibling选择当前元素后的兄弟元素,比如出发框的Xpath表达式如下:
.//*[text()= '出发']/following-sibling::input"
也可以用下面Xpath
//div[@id='js_flighttype_tab_domestic']//input[@name='fromCity']


/**
* @author Hjianhui
* 12306 2016-08-05
*
*/
public class test{ public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); try{
driver.get("http://www.qunar.com/");
driver.manage().window().maximize();
//输入出发地方
driver.findElement(By.xpath(".//*[text()= '出发']/following-sibling::input")).clear();
driver.findElement(By.xpath(".//*[text()= '出发']/following-sibling::input")).sendKeys("北京"); ////输入到达地方
driver.findElement(By.xpath(".//*[text()= '到达']/following-sibling::input")).clear();
driver.findElement(By.xpath(".//*[text()= '到达']/following-sibling::input")).sendKeys("广州"); if(isElementPresent(driver, By.xpath(".//*[@id='closeXI20']")))
driver.findElement(By.xpath(".//*[@id='closeXI20']")).click(); driver.findElement(By.id("js_domestic_fromdate")).clear();
driver.findElement(By.id("js_domestic_fromdate")).sendKeys("2016-08-20"); //点击立即搜索
driver.findElement(By.xpath(".//span[@class = 'p_btn']/button")).click(); }catch (Exception e){
e.printStackTrace();
}
driver.quit();
} public static boolean isElementPresent(WebDriver driver, By by) {
try {
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
由于在输入到达地方的时候,可能会有下图挡住了立即搜索,导致立即搜索不可见,因此用isElementPresent()函数判断该图下的右上角图标是否出现,如果出现,点击取消他,然后再点击立即搜索

Selenium Webdriver——去哪儿网输入实例的更多相关文章
- 去哪儿网输入框三种输入方式(selenium webdriver 干货)
在机票预定的页面,输入出发城市和到达城市输入框的时候, 发现直接使用sendkeys不好使, 大部分情况出现输入某城市后没有输入进去, 经过几天的研究,发现可以采取三种方式: 1. 先点击输入框,待弹 ...
- 输入框三种输入方式(selenium webdriver 干货)
在机票预定的页面,输入出发城市和到达城市输入框的时候, 发现直接使用sendkeys不好使, 大部分情况出现输入某城市后没有输入进去, 经过几天的研究,发现可以采取三种方式: 1. 先点击输入框,待弹 ...
- Selenium WebDriver TestNg Maven Eclipse java 简单实例
环境准备 前提条件Eclipse 已经安装过 TestNg ,Maven 插件 新建一个普通的java项目 点击右键 configure->convert to Maven Project 之后 ...
- selenium webdriver启动Chrome浏览器后无法输入网址的解决办法
通过selenium webdriver启动Chrome浏览器,脚本如下: from selenium import webdriver browser = webdriver.Chrome() br ...
- Selenium WebDriver java 简单实例
开发环境 JDK 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html Eclipse: 下载地址:http ...
- selenium webdriver——JS对Input执行输入
直接设置value属性, 此方法主要应对输入框自动补全以及readonly属性的element,sendkeys不稳定 比如: Demo:用JS输入 import org.openqa.seleniu ...
- (java)selenium webdriver学习--通过id、name定位,输入内容,搜索,关闭操作、通过tagname查找元素
selenium webdriver学习--通过id.name定位,输入内容,搜索,关闭操作:通过tagname查找元素 打开谷歌浏览器,输入不同的网站,搜索框的定位含有不同元素(有时为id,有时为n ...
- 一个selenium笔试题——去哪网首页获取符合要求的url并保存
今天在群里看到这样一个笔试题:请使用任何熟悉的面向对象编程语言,编写代码,获取http://www.qyer.com页面中,所有</a>标签"href"属性值包含英文单 ...
- selenium webdriver (python)的基本用法一
阅在线 AIP 文档:http://selenium.googlecode.com/git/docs/api/py/index.html目录一.selenium+python 环境搭建........ ...
随机推荐
- linux挂载windows共享文件夹出错,提示mount error(13): Permission denied
完整的可以工作的命令行: mount -v -t cifs -o username=clouder,password=123456,iocharset=utf8,sec=ntlm //172.28.1 ...
- ExecutorService对象的shutdown()和shutdownNow()的区别
可以关闭 ExecutorService,这将导致其拒绝新任务.提供两个方法来关闭 ExecutorService. shutdown() 方法在终止前允许执行以前提交的任务; shutdownNow ...
- docker的搭建和简单应用
dockerserver端安装 先下载docker的yum源 wget http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ...
- SSH使用主机名访问
比如说A电脑已经和B电脑实现了ssh免密码登陆!但是A电脑通过 ssh B电脑的主机名称 不行! 解决办法: 01.修改A电脑中的hosts文件 vim /etc/hosts 02.进入编辑界面 ...
- Jenkins插件开发(三)-- 插件编写
在上一篇blog 中我们介绍了如何创建我们第一个jenkins插件,在这一篇blog继续介绍在开发我们的插件过程中需要注意的一些问题. 扩展点选择 Jenkings插件是基于扩展点来实现的,比如基于B ...
- Jenkins插件开发(四)-- 插件发布
上一篇blog介绍了插件开发中要注意的一些问题, 我们再来介绍插件开发完成后,如何上传到jenkins的插件中心(这里假设你的代码是放在github上的,使用svn或其他版本管理工具的请参考其他文章) ...
- SocketServer模块 《Python核心编程(第3版)》——2.5
本文内容参考文章地址: https://m.aliyun.com/yunqi/articles/93088/ SocketServer模块 SocketServer是标准库中的一个高级模块(Pytho ...
- Linux 键盘输入#的时候变成£
/********************************************************************************* * Linux 键盘输入#的时候变 ...
- hdu 3613 Best Reward
After an uphill battle, General Li won a great victory. Now the head of state decide to reward him w ...
- 【项目经验】macpro上安装office办公软件并破解
链接: https://pan.baidu.com/s/1i5hyKO9 密码: 7zjf 如果本机原有office,先卸载 双击pkg文件安装office for Mac 2016 安装完不要做打开 ...