python selenium處理JS只讀(12306)

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.titleprint("passed")
except Exception as e:print("failed")
driver.quit()

?

轉載于:https://www.cnblogs.com/yye2010/p/8651672.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389971.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389971.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389971.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Mac上使用Jenv管理多個JDK版本

使用Java時會接觸到不同的版本。大多數時候我在使用Java 8,但是因為某些框架或是工具的要求,這時不得不讓Java 7上前線。一般情況下是配置JAVA_HOME,指定不同的Java版本,但是這需要人為手動的輸入。如果又要選擇其他版本&#xff…

交互式和非交互式_發布交互式劇情

交互式和非交互式Python中的Visual EDA (Visual EDA in Python) I like to learn about different tools and technologies that are available to accomplish a task. When I decided to explore data regarding COVID-19 (Coronavirus), I knew that I would want the abilit…

5886. 如果相鄰兩個顏色均相同則刪除當前顏色

5886. 如果相鄰兩個顏色均相同則刪除當前顏色 總共有 n 個顏色片段排成一列,每個顏色片段要么是 ‘A’ 要么是 ‘B’ 。給你一個長度為 n 的字符串 colors ,其中 colors[i] 表示第 i 個顏色片段的顏色。 Alice 和 Bob 在玩一個游戲,他們 輪…

Sunisoft.IrisSkin.SkinEngine 設置winform皮膚

Sunisoft.IrisSkin.SkinEngine se; se new Sunisoft.IrisSkin.SkinEngine { SkinAllForm true, SkinFile "..\..\skin\EmeraldColor2.ssk" };Sunisoft.IrisSkin.SkinEngine skin new Sunisoft.IrisSkin.SkinEngine(); //具體樣式文件 地址,可以自行修…

docker 相關操作

docker-compose down //關閉所有容器 docker-compose up //開啟所有容器docker-compose restart //重啟所有容器單獨更新某個容器時用腳本$ docker ps // 查看所有正在運行容器 $ docker stop containerId // containerId 是容器的ID$ docker ps -a // 查看所有容器 $…

電子表格轉換成數據庫_創建數據庫,將電子表格轉換為關系數據庫,第1部分...

電子表格轉換成數據庫Part 1: Creating an Entity Relational Diagram (ERD)第1部分:創建實體關系圖(ERD) A Relational Database Management System (RDMS) is a program that allows us to create, update, and manage a relational database. Structured Query …

【Vue.js學習】生命周期及數據綁定

一、生命后期 官網的圖片說明: Vue的生命周期總結 var app new Vue({el:"#app", beforeCreate: function(){console.log(1-beforeCreate 初始化之前);//加載loading},created: function(){console.log(2-created 創建完成);//關閉loading},be…

5885. 使每位學生都有座位的最少移動次數

5885. 使每位學生都有座位的最少移動次數 一個房間里有 n 個座位和 n 名學生,房間用一個數軸表示。給你一個長度為 n 的數組 seats ,其中 seats[i] 是第 i 個座位的位置。同時給你一個長度為 n 的數組 students ,其中 students[j] 是第 j 位…

Springboot(2.0.0.RELEASE)+spark(2.1.0)框架整合到jar包成功發布(原創)!!!

一、前言 首先說明一下,這個框架的整合可能對大神來說十分容易,但是對我來說十分不易,踩了不少坑。雖然整合的時間不長,但是值得來紀念下!!!我個人開發工具比較喜歡IDEA,創建的sprin…

求一個張量的梯度_張量流中離散策略梯度的最小工作示例2 0

求一個張量的梯度Training discrete actor networks with TensorFlow 2.0 is easy once you know how to do it, but also rather different from implementations in TensorFlow 1.0. As the 2.0 version was only released in September 2019, most examples that circulate …

docker環境 快速使用elasticsearch-head插件

docker環境 快速使用elasticsearch-head插件 #elasticsearch配置 #進入elk容器 docker exec -it elk /bin/bash #head插件訪問配置 echo #head插件訪問# http.cors.enabled: true http.cors.allow-origin: "*" >>/etc/elasticsearch/elasticsearch.yml#重啟el…

476. 數字的補數

476. 數字的補數 給你一個 正 整數 num ,輸出它的補數。補數是對該數的二進制表示取反。 例 1:輸入:num 5 輸出:2 解釋:5 的二進制表示為 101(沒有前導零位),其補數為 010。所以你…

zabbix網絡發現主機

1 功能介紹 默認情況下,當我在主機上安裝agent,然后要在server上手動添加主機并連接到模板,加入一個主機組。 如果有很多主機,并且經常變動,手動操作就很麻煩。 網絡發現就是主機上安裝了agent,然后server自…

python股市_如何使用python和破折號創建儀表板來主導股市

python股市始終關注大局 (Keep Your Eyes on the Big Picture) I’ve been fascinated with the stock market since I was a little kid. There is certainly no shortage of data to analyze, and if you find an edge you can make some easy money. To stay on top of the …

阿里巴巴開源 Sentinel,進一步完善 Dubbo 生態

為什么80%的碼農都做不了架構師?>>> 阿里巴巴開源 Sentinel,進一步完善 Dubbo 生態 Sentinel 開源地址:https://github.com/alibaba/Sentinel 轉載于:https://my.oschina.net/dyyweb/blog/1925839

數據結構與算法 —— 鏈表linked list(01)

鏈表(維基百科) 鏈表(Linked list)是一種常見的基礎數據結構,是一種線性表,但是并不會按線性的順序存儲數據,而是在每一個節點里存到下一個節點的指針(Pointer)。由于不必須按順序存儲,鏈表在插入的時候可以…

離群值如何處理_有理處理離群值的局限性

離群值如何處理ARIMA models can be quite adept when it comes to modelling the overall trend of a series along with seasonal patterns.ARIMA模型可以很好地建模一系列總體趨勢以及季節性模式。 In a previous article titled SARIMA: Forecasting Seasonal Data with P…

網絡爬蟲基礎練習

0.可以新建一個用于練習的html文件,在瀏覽器中打開。 1.利用requests.get(url)獲取網頁頁面的html文件 import requests newsurlhttp://news.gzcc.cn/html/xiaoyuanxinwen/ res requests.get(newsurl) #返回response對象 res.encodingutf-8 2.利用BeautifulSoup的H…

10生活便捷:購物、美食、看病時這樣搜,至少能省一半心

本次課程介紹實實在在能夠救命、省錢的網站,解決了眼前這些需求后,還有“詩和遠方”——不花錢也能點亮自己的生活,獲得美的享受! 1、健康醫療這么搜,安全又便捷 現在的醫療市場確實有些混亂,由于醫療的專業…

ppt圖表圖表類型起始_梅科圖表

ppt圖表圖表類型起始There are different types of variable width bar charts but two are the most popular: 1) Bar Mekko chart; 2) Marimekko chart.可變寬度條形圖有不同類型,但最受歡迎的有兩種:1)Mekko條形圖; 2)Marimekko圖表。 Th…