def
choose_ticket(
self
):
if
self
.status
=
=
2
:
print
(
'='
*
30
)
print
(
'###开始进行日期及票价选择###'
)
while
self
.driver.title.find(
"确认订单"
)
=
=
-
1
:
try
:
buybutton
=
self
.driver.find_element_by_class_name(
'buybtn'
).text
if
buybutton
=
=
'提交缺货登记'
:
self
.status
=
2
# 没有进行更改操作
self
.driver.get(target_url)
# 刷新页面 继续执行操作
elif
buybutton
=
=
'立即预定'
:
# 点击立即预定
self
.driver.find_element_by_class_name(
'buybtn'
).click()
self
.status
=
3
elif
buybutton
=
=
'立即购买'
:
self
.driver.find_element_by_class_name(
'buybtn'
).click()
self
.status
=
4
elif
buybutton
=
=
'选座购买'
:
self
.driver.find_element_by_class_name(
'buybtn'
).click()
self
.status
=
5
except
:
print
(
'###没有跳转到订单结算界面###'
)
title
=
self
.driver.title
if
title
=
=
'选座购买'
:
# 选座购买的逻辑
self
.choice_seats()
elif
title
=
=
'确认订单'
:
# 实现下单的逻辑
while
True
:
# 如果标题为确认订单
print
(
'正在加载.......'
)
# 如果当前购票人信息存在 就点击
if
self
.isElementExist(
'//*[@id="container"]/div/div[9]/button'
):
# 下单操作
self
.check_order()
break