【发布时间】: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