from selenium import webdriver
from time import sleep
# 谷歌浏览器驱动
path = r"E:\software\python_Related\chromedriver.exe"
driver = webdriver.Chrome(executable_path=path)
driver.get("https://www.12306.cn/index/")
from selenium.webdriver.common.keys import Keys
# 通过 js代码 移除 只读属性
# document.getElementById('train_date').removeAttribute('readonly')
# driver.execute_script("document.getElementById('train_date').removeAttribute('readonly')")
sleep(4)
#readonly 属性 只能读取
search = driver.find_element_by_id("search_one")
tran = driver.find_element_by_id("train_date")
# arguments[0].removeAttribute('readonly');
driver.execute_script("arguments[0].removeAttribute('readonly');",tran)
driver.find_element_by_id("train_date").clear()
driver.find_element_by_id("train_date").send_keys("2020-08-10")
driver.find_element_by_id("fromStationText").send_keys("北")
driver.find_element_by_id("fromStationText").send_keys(Keys.ENTER)
sleep(1)
driver.find_element_by_id("fromStationText").send_keys(Keys.TAB)
driver.find_element_by_id("toStationText").send_keys("上")
driver.find_element_by_id("toStationText").send_keys(Keys.ENTER)
sleep(1)
# search.click()
#模拟鼠标
from selenium.webdriver.common.action_chains import ActionChains
# 根据元素偏移量定位
# ActionChains(driver).move_by_offset(160,450).perform()
ActionChains(driver).move_to_element_with_offset(search,10,10).perform()
ActionChains(driver).click().perform()
12306查询测试:https://www.12306.cn/index/
最新推荐文章于 2021-06-22 13:49:35 发布