【问题标题】:convert python selenium to just selenium ide commands将 python selenium 转换为仅 selenium ide 命令
【发布时间】:2016-05-17 03:20:28
【问题描述】:

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

  • 查找当前所选日期
  • 选择下一个可用日期
  • 如果当月没有找到可用的日期,请按下一步转到下个月

我的问题是,我也只想在这个人只需要记录他们的步骤的地方包含一个 selenium ide 版本。有没有办法将我下面的代码转换为 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

【问题讨论】:

  • 我知道这并不能回答您的问题,但在您在长期计划中考虑 IDE 之前,可能值得检查一下stackoverflow.com/questions/19683100/…
  • 嗨,andrew,我之前确实看过这个页面。我想使用 IDE,这样我就可以向那些不熟悉自动化的人展示一种快速进入它的方法,然后再使用 Web 驱动程序,当我们走得更高级时。有些测试人员没有你所看到的开发背景
  • 好的,但我认为 Selenium 的态度是 WebDriver 是标准而不是高级方法,非开发人员应该使用许多框架或 DSL 中的一种。在管理过非技术测试人员之后,我会说他们使用体面的 DSL 至少可以像使用 IDE 一样高效。

标签: python python-2.7 selenium selenium-webdriver selenium-ide


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-02-23
    • 1970-01-01
    • 2013-10-21
    • 2018-01-25
    • 2017-03-27
    • 2017-06-26
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    相关资源
    最近更新 更多