【问题标题】:Safari WebDriver can't submit in a text boxSafari WebDriver 无法在文本框中提交
【发布时间】:2014-08-04 23:28:30
【问题描述】:

我正在尝试使用 Selenium 测试一个简单的 webapp。用例是:

  • 开始here
  • 点击第一个列表中的“待办事项”链接
  • 在文本框中输入一些内容
  • 点击按钮

然后,列表中的最后一项应该是输入的值,并且文本框应该是空的。

在 OS X (10.9.4) 上的 Safari (v7.0.5 (9537.77.4)) 中,手动执行此操作可正常工作。这在使用 Selenium 驱动 Chrome 时也有效。但是,当通过 Safari WebDriver 使用 Selenium 时,添加的项目只是一个空字符串。

奇怪的是input元素的value属性在WebDriver键入文本后具有正确的值;该值不会像手动执行操作时那样添加到列表中。

以下是重现该行为的代码。有人有什么见解吗?

from selenium import webdriver

url = 'http://mithril-test.cos.io/basic/'

d = webdriver.Safari()

    try:
    # navigate to 'http://mithril-test.cos.io/basic/'
    d.get(url)

    # click 'todo' link
    d.find_element_by_link_text('todo').click()

    # type in 'whatevs' in the input field
    input_text = 'test'
    d.find_element_by_tag_name('input').send_keys(input_text)

    # the 'value' attribute of the input field is the thing we just typed
    assert d.find_element_by_tag_name('input').get_attribute('value') == input_text

    # click the submit button
    d.find_element_by_tag_name('button').click()

    todo_text = d.find_elements_by_tag_name('ul')[1].text
    # passes: the list is 'one' 'two': incorrect behavior
    assert todo_text == 'one\ntwo'
    # fails: the list should be 'one' 'two' plus the thing we typed in: correct behavior
    assert todo_text == 'one\ntwo\n' + input_text

except:
    raise

finally:
    d.close()

【问题讨论】:

  • 我看不到value 部分。
  • @Ant 很抱歉,我不明白你的意思。我的问题有什么可以澄清或解决的吗?

标签: selenium safari selenium-webdriver


【解决方案1】:

问题在于Safari WebDriver 的实现,如in this issue 所述。特别是,打字行为是在 JavaScript 中实现的,这会导致许多限制,如 here 所述。

我目前的解决方法是在测试本身中触发更改事件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 2023-03-20
    • 1970-01-01
    • 2013-05-18
    • 2019-07-15
    相关资源
    最近更新 更多