将python selenium转换为selenium ide命令

Bru*_*dit 5 python selenium selenium-ide python-2.7 selenium-webdriver

下面我有一个能够执行以下操作的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
Run Code Online (Sandbox Code Playgroud)

Akc*_*tor 0

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