我使用的是最新的Selenium RC Python Client和Selenium RC Server。我想点击具有以下HTML代码的网页按钮:Selenium CSS定位器,包含Firefox和IE上的onclick
<input type="submit" id="b1" value="Button1 - Standard" onclick="javascript: alert('button1')">
以下Python代码点击了使用CSS定位xxx
在Firefox 1以上按钮,但不能在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
我完全知道,我有唯一ID这个CSS,我不需要像类型和属性的onclick(我只是好奇为什么会发生这种情况)。
总之,这篇文章特别针对一个Selenium CSS定位器,它具有onclick作为属性,它可以在Firefox上使用,但不能在IE上使用。有没有人知道这是为什么?
你确定Firefox和IE8呈现相同的HTML吗?也许IE8正在做一些奇怪的事情,并改变标记。如果你在两个浏览器中检查,你看到相同的标记吗? – 2012-01-19 00:11:10
实际上,对于Firefox,我可以清楚地看到使用萤火虫的源代码,但不能使用IE浏览器。它不仅仅是'onclick',甚至'onchange'和有时'style'属性都不起作用......我相信有一些属性在CSS中不能使用,但可以被Xpath使用! – abarik 2012-01-19 19:23:04