【问题标题】:Selenium, CSS, and Python: not being able to view default text in a textboxSelenium、CSS 和 Python:无法在文本框中查看默认文本
【发布时间】: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


    【解决方案1】:

    使用selenium.is_visible(locator)。如果不起作用,请使用selenium.is_text_present(value)if (Expectedvalue == selobj.get_value(parameter))

    如果还是不行,刷新页面试试上面的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多