【发布时间】:2011-10-11 07:08:19
【问题描述】:
我有一个文本字段,其中包含默认文本'abc'。当我在此字段内写入内容或光标位于此字段内时,默认文本会消失。该字段的底层 HTML 标记是:
<div id="InputDefault" class="defaultText" style="visibility: visible;">abc</div>
现在,手动一切正常。我正在Selenium 中编写一个测试用例,以检查字段为空时是否出现默认文本。但是在测试用例中,它有时会起作用,但更多时候会失败。我写了以下函数:
#I first delete the text in the field (I have used a text element)/
self.se.type(#I first delete the text in the field (I have used a text element).
self.se.type(locators["search_field_header"], "")
#Then I focus on the field.
self.se.set_cursor_position("headerParam", "")
#Then I focus on the field
self.se.set_cursor_position("headerParam",0)
#Press the TAB key to move focus away from the search field to get default text.
self.se.key_press_native("9")
self.se.set_speed(1000)
is_footer_default_text_present = self.is_element_available("InputDefault")
但这在某种程度上不起作用。有什么问题,有没有更好/更可靠的解决方案?
【问题讨论】:
标签: python css selenium selenium-rc