【发布时间】:2012-01-19 16:33:45
【问题描述】:
我正在使用最新的 Selenium RC Python 客户端和 Selenium RC 服务器。我正在尝试单击具有以下 HTML 标记的网页上的按钮:
<input type="submit" id="b1" value="Button1 - Standard" onclick="javascript: alert('button1')">
以下 Python 代码在 Firefox 上使用 CSS Locator xxx 1st 点击上述按钮,但在 IE 上没有。
在 Firefox 上:
from selenium import selenium
s1 = selenium('myhost_ip_address', 4444, '*chrome', 'http://mypage_with_button.com')
print s1.is_element_present('css=input[value="Button1 - Standard"][type="submit"][id="b1"][onclick="javascript: alert(\'button1\')"]')
# Returns True
在 IE8 上:
# NOTE: On IE, you might have to click on the notification 'To help protect your security... ActiveX controls that could....' and Allow Blocked Contents if needed
from selenium import selenium
s1 = selenium('myhost_ip_address', 4444, '*chrome', 'http://mypage_with_button.com')
print s1.is_element_present('css=input[value="Button1 - Standard"][type="submit"][id="b1"][onclick="javascript: alert(\'button1\')"]')
# Returns False
我完全知道我有这个 css 的唯一 ID,我不需要像 type 和 onclick 这样的属性(我只是好奇为什么会这样)。
总而言之,这篇文章特别适用于具有 onclick 作为属性的 Selenium CSS 定位器,它适用于 Firefox,但不适用于 IE。有没有人知道为什么会这样??
【问题讨论】:
-
您确定 Firefox 和 IE8 呈现相同的 html 吗?也许 IE8 正在做一些奇怪的事情并更改标记。如果您在两个浏览器中进行检查,您会看到相同的标记吗?
-
实际上,对于 Firefox,我可以使用 firebug 清晰详细地看到 Source,但 IE 看不到。它不只是
onclick,甚至onchange和有时style属性都不起作用...我确信某些属性不能在CSS 中使用,但可以被Xpath 使用!!
标签: python selenium internet-explorer-8 css-selectors