12306为例

js = "document.getElementById('train_date').removeAttribute('readonly');"
driver.execute_script(js)
time2获取当前时间 tomorrow_time 获取明天时间
from selenium import webdriver
import time
import datetime
time1=datetime.datetime.now().strftime("%Y-%m-%d.%H%M%S.%f")
time2=datetime.datetime.now().strftime("%Y-%m-%d")
oneday = datetime.timedelta(days=1)
tomorrow_time = datetime.datetime.now() + oneday
tomorrow_time = datetime.datetime.strftime(tomorrow_time, '%Y-%m-%d') driver = webdriver.Firefox()
# driver.maximize_window()
driver.implicitly_wait(6)
#页面不稳定
driver.get("http://www.12306.cn/mormhweb/")
driver.find_element_by_xpath("html/body/div[1]/div[4]/div[3]/div[1]/ul/li[3]/a").click()
time.sleep(1)
driver.switch_to.window(driver.window_handles[1])
driver.find_element_by_id("fromStationText").clear()
driver.find_element_by_id("fromStationText").send_keys('上海')
driver.find_element_by_xpath("//div[@id='form_cities']/div[@id='panel_cities']/div[@id='citem_0']").click()
time.sleep(2)
driver.find_element_by_id("toStationText").clear()
driver.find_element_by_id("toStationText").send_keys('九江')
driver.find_element_by_xpath("//div[@id='form_cities']/div[@id='panel_cities']/div[@id='citem_0']").click()
# 去除js read-only属性
js = "document.getElementById('train_date').removeAttribute('readonly');"
driver.execute_script(js)
# 用js方法输入日期
js_value = 'document.getElementById("train_date").value="'+time2+'"'
driver.execute_script(js_value)
time.sleep(1)
driver.find_element_by_id("a_search_ticket").click()
time.sleep(2)
try:
assert u'车票预订 | 客运服务 | 铁路客户服务中心'== driver.title
print("passed")
except Exception as e:
print("failed")
driver.quit()

最新文章

  1. How threads differ from processes
  2. Android中的Shape使用总结
  3. 快速诊断Linux性能
  4. Install the 64bit library in Ubuntu13.10
  5. js实现简单易用的上下无缝滚动效果
  6. jdbcTemplate 获取数据表结构
  7. WPF自定义窗口(Windows Server 2012 Style)
  8. 基于GBT28181:SIP协议组件开发-----------第三篇SIP注册流程分析实现
  9. WinCE 5.0模拟器,在 win7 下安装后, VS2008里不显示
  10. PHP安装phpredis扩展
  11. iOS 单利模式实现/优缺点
  12. libev学习代码
  13. css 的一些知识点的整理
  14. 一步一步 copy163: 网易严选 ---- vue-cli
  15. 如何安装mariadb服务器和解决 can't connect to local mysql server through socket...
  16. 根据传智写的SqlHelper
  17. 001.Linux开机启动过程
  18. 02:MongoDB操作
  19. Django之WSGI 和MVC/MTV
  20. 解决sublime的中文乱码

热门文章

  1. IO流8 --- 使用FileReader和FileWriter实现文本文件的复制 --- 技术搬运工(尚硅谷)
  2. 【风马一族_win10设置热点】win10无法开启热点怎么办
  3. 100个常用的原生JavaScript函数
  4. 微信小程序--轮播图,标题,盒子,tab栏的合成例子
  5. web标准中定义id与class有什么区别吗
  6. C# System.Timers.Timer中的坑,程序异常退出后timer依然运行问题
  7. WEB性能测试用例设计
  8. 2018-8-10-C#-快速释放内存的大数组
  9. JS实现AES加密并与PHP互通的方法分析
  10. Liferay Model Hints