论坛首页 Java企业应用论坛

selenium的getText在ie中会把不可见的内容也取到

浏览 2106 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-03-31  
最近在使用selenium做自动测试,发现对于不可见内容,在firefox和ie中
的表现不一样,firefox只返回可见的内容,而ie却将不可见内容也一起返
回,大家有用到的时候要注意。

下面是一个小例子:

测试用的页面如下:其中"show"文字是可见的,"hide"文字是不可见的。
<html>
<head>
	<title>testV</title>
</head>

<body>
	<div id="all">
		<div id="visible">show</div>
		<div id="invisible" style="display:none">hide</div>
	</div>
</body>
</html>


测试代码如下,其中参数是使用的浏览器,用firefox测输入"firefox",用ie
测输入"iexplore"
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;

public class Test {
	public static void main(String[] args) throws Exception {
		DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, args[0], "http://192.168.20.128");
		
		SeleniumServer server = new SeleniumServer();
		server.start();
		selenium.start();
		selenium.open("test.html");
		
		selenium.getText("all");
		selenium.isElementPresent("visible");
		selenium.isElementPresent("invisible");
		selenium.isVisible("visible");
		selenium.isVisible("invisible");
		
		selenium.stop();
		server.stop();
	}
}


用firefox测的结果如下:注意selenium.getText("all")得到的是"show",isElementPresent
都返回true,"visible"的isVisible返回true,"invisible"的isVisible返回false

12:05:45.373 INFO - Command request: open[test.html, ] on session d79b5f22b4cd40
25bfbe00ac6df14e3c
12:05:45.454 INFO - Got result: OK on session d79b5f22b4cd4025bfbe00ac6df14e3c
12:05:45.456 INFO - Command request: getText[all, ] on session d79b5f22b4cd4025b
fbe00ac6df14e3c
12:05:45.468 INFO - Got result: OK,show on session d79b5f22b4cd4025bfbe00ac6df14
e3c
12:05:45.470 INFO - Command request: isElementPresent[visible, ] on session d79b
5f22b4cd4025bfbe00ac6df14e3c
12:05:45.482 INFO - Got result: OK,true on session d79b5f22b4cd4025bfbe00ac6df14
e3c
12:05:45.484 INFO - Command request: isElementPresent[invisible, ] on session d7
9b5f22b4cd4025bfbe00ac6df14e3c
12:05:45.498 INFO - Got result: OK,true on session d79b5f22b4cd4025bfbe00ac6df14
e3c
12:05:45.500 INFO - Command request: isVisible[visible, ] on session d79b5f22b4c
d4025bfbe00ac6df14e3c
12:05:45.514 INFO - Got result: OK,true on session d79b5f22b4cd4025bfbe00ac6df14
e3c
12:05:45.517 INFO - Command request: isVisible[invisible, ] on session d79b5f22b
4cd4025bfbe00ac6df14e3c
12:05:45.532 INFO - Got result: OK,false on session d79b5f22b4cd4025bfbe00ac6df1
4e3c

用ie测的结果如下:注意selenium.getText("all")得到的是"show hide",其他和firefox
一样。

11:58:00.576 INFO - Command request: open[test.html, ] on session 80a09c3dfde642
eba6b91615320ee2e1
11:58:01.357 INFO - Got result: OK on session 80a09c3dfde642eba6b91615320ee2e1
11:58:01.357 INFO - Command request: getText[all, ] on session 80a09c3dfde642eba
6b91615320ee2e1
11:58:01.466 INFO - Got result: OK,show
hide
on session 80a09c3dfde642eba6b91615320ee2e1
11:58:01.466 INFO - Command request: isElementPresent[visible, ] on session 80a0
9c3dfde642eba6b91615320ee2e1
11:58:01.576 INFO - Got result: OK,true on session 80a09c3dfde642eba6b91615320ee
2e1
11:58:01.591 INFO - Command request: isElementPresent[invisible, ] on session 80
a09c3dfde642eba6b91615320ee2e1
11:58:01.701 INFO - Got result: OK,true on session 80a09c3dfde642eba6b91615320ee
2e1
11:58:01.701 INFO - Command request: isVisible[visible, ] on session 80a09c3dfde
642eba6b91615320ee2e1
11:58:02.232 INFO - Got result: OK,true on session 80a09c3dfde642eba6b91615320ee
2e1
11:58:02.232 INFO - Command request: isVisible[invisible, ] on session 80a09c3df
de642eba6b91615320ee2e1
11:58:02.607 INFO - Got result: OK,false on session 80a09c3dfde642eba6b91615320e
e2e1
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics