self.now_month = datetime.date.today().month
self.leave_month = int(self.depart_time.split(‘-’)[0])
self.leave_day = int(self.depart_time.split(‘-’)[1])
self.driver = webdriver.Chrome()
def _login(self):
self.driver.get(self.login_url)
窗口最大化
#self.driver.maximize_window()
设置窗口大小
self.driver.set_window_size(1300,800)
#print(‘调整前尺寸:’, self.driver.get_window_size())
#显式等待
#这里进行手动登录,可以扫码,也可以输入账号密码点击登录
WebDriverWait(self.driver,1000).until(EC.url_to_be(self.init_my_url))
print(‘登录成功!’)
def _pop_window(self):
time.sleep(1)
self.driver.find_element_by_xpath(‘//*[@class=“dzp-confirm”]/div[2]/div[3]/a’).click()
def _enter_order_ticket(self):
action = ActionChains(self.driver) # 实例化一个动作链对象
element = self.driver.find_element_by_link_text(‘车票’)
鼠标移动到 ‘车票’ 元素上的中心点
action.move_to_element(element).perform()
点击’单程’
self.driver.find_element_by_xpath(‘//*[@id=“J-chepiao”]/div/div[1]/ul/li[1]/a’).click()
消除第二次弹窗
self.driver.find_element_by_link_text(‘确认’).click()
def _search_ticket(self):
#出发地输入
self.driver.find_element_by_id(“fromStationText”).click()
self.driver.find_element_by_id(“fromStationText”).send_keys(self.from_station)
self.driver.find_element_by_id(“fromStationText”).send_keys(Keys.ENTER)
#目的地输入
self.driver.find_element_by_id(“toStationText”).click()
self.driver.find_element_by_id(“toStationText”).send_keys(sel