gpt4 book ai didi

python - 将 python selenium 转换为 selenium ide 命令

转载 作者:太空狗 更新时间:2023-10-30 01:37:38 33 4
gpt4 key购买 nike

下面我有一个能够执行以下操作的 python 脚本:

  • 找到当前选择的日期
  • 选择下一个可用日期
  • 如果在该月内找不到可用日期,请按下一步转到下个月

我的问题是,我也只想在人们只需要记录他们的步骤的地方包含一个 selenium ide verson。有没有办法将我下面的代码转换为 IDE 中的命令、目标和值,以便它做同样的事情?如果您可以按顺序提供命令、目标和值的列表,那将非常有帮助。

我正在测试的网站是 www.jet2.com,它与出发日期有关。

之所以只想在IDE中转换,是为了以后手动测试时,我可以直接使用IDE回放来执行其余的测试。 claendar 是我使用 python 方法解决的唯一故障。

# select date
datepicker = driver.find_element_by_id("departure-date-selector")
actions.move_to_element(datepicker).click().perform()

# find the calendar, month and year picker and the current date
calendar = driver.find_element_by_id("departureDateContainer")
month_picker = Select(calendar.find_element_by_class_name("ui-datepicker-month"))
year_picker = Select(calendar.find_element_by_class_name("ui-datepicker-year"))
current_date = calendar.find_element_by_class_name("ui-datepicker-current-day")

# printing out current date
month = month_picker.first_selected_option.text
year = year_picker.first_selected_option.text
print("Current date: {day} {month} {year}".format(day=current_date.text, month=month, year=year))

# see if we have an available date in this month
try:
next_available_date = current_date.find_element_by_xpath("following::td[@data-handler='selectDay' and ancestor::div/@id='departureDateContainer']")
print("Found an available date: {day} {month} {year}".format(day=next_available_date.text, month=month, year=year))
next_available_date.click()
except NoSuchElementException:
# looping over until the next available date found
while True:
# click next, if not found, select the next year
try:
calendar.find_element_by_class_name("ui-datepicker-next").click()
except NoSuchElementException:
# select next year
year = Select(calendar.find_element_by_class_name("ui-datepicker-year"))
year.select_by_visible_text(str(int(year.first_selected_option.text) + 1))

# reporting current processed month and year
month = Select(calendar.find_element_by_class_name("ui-datepicker-month")).first_selected_option.text
year = Select(calendar.find_element_by_class_name("ui-datepicker-year")).first_selected_option.text
print("Processing {month} {year}".format(month=month, year=year))

try:
next_available_date = calendar.find_element_by_xpath(".//td[@data-handler='selectDay']")
print("Found an available date: {day} {month} {year}".format(day=next_available_date.text, month=month, year=year))
next_available_date.click()
break
except NoSuchElementException:
continue

最佳答案

我想我不可能使用纯 Selenium IDE,但您可以使用插件,例如 FlowControlSelBlocks获得 if-else、goto 和循环功能以及类似 javascript 的条件、可调用函数、错误捕获和 JSON/XML 驱动的参数化。

关于python - 将 python selenium 转换为 selenium ide 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35253102/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com