我已经找到了解决我自己的问题。 当您使用Selenium运行测试时,它会启动两个窗口: 1)执行所有命令的Selenium窗口 2)用于测试网站的浏览器窗口。
当您尝试通过JavaScript函数来获取有关窗口2的信息,你需要做到以下几点: selenium.browserbot.getCurrentWindow()
要通过硒得到一个浏览器窗口的跨浏览器的整个高度,你需要以下脚本:
function getPageHeight(){
$scrOfY = 0;
$test = $this->getEval("typeof(selenium.browserbot.getCurrentWindow().pageYOffset)");
if(strcmp($test,"number") == 0) {
//Netscape compliant
$scrOfY = (int)$this->getEval("selenium.browserbot.getCurrentWindow().pageYOffset;");
//scrOfX = window.pageXOffset;
} else if((bool)$this->getEval("selenium.browserbot.getCurrentWindow().document.body != null") && (bool)$this->getEval("selenium.browserbot.getCurrentWindow().document.body.scrollTop != null")) {
//DOM compliant
$scrOfY = (int)$this->getEval("selenium.browserbot.getCurrentWindow().document.body.scrollTop;");
//scrOfX = document.body.scrollLeft;
} else if((bool)$this->getEval("selenium.browserbot.getCurrentWindow().document.documentElement != null") && (bool)$this->getEval("selenium.browserbot.getCurrentWindow().document.documentElement.scrollTop != null")) {
//IE6 standards compliant mode
$scrOfY = (int)$this->getEval("selenium.browserbot.getCurrentWindow().document.documentElement.scrollTop;");
//scrOfX = document.documentElement.scrollLeft;
}
if(!$scrOfY || $scrOfY <= 0)
$scrOfY = $this->getEval("selenium.browserbot.getCurrentWindow().document.body.offsetHeight");
return $scrOfY;
}
哼哼......我会试试这个谢谢。对于Q和A – 2010-05-05 19:02:53
对自己的问题很好的回答! – StefanE 2010-05-20 12:52:10