下面我有一个能够执行以下操作的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
答案 0 :(得分:0)
我想我用纯Selenium IDE是不可能的,但是你可以使用像这样的插件 FlowControl或SelBlocks获取if-else,goto和loop功能 以及类似javascript的条件,可调用函数,错误捕获和JSON / XML驱动的参数化。