|
请问由jQuery改变的html element属性如何用HtmlUnit测试? 请看下面代码, 代码中等image加载完成后, 跟据image的实际宽度来动态的改变image caption的宽度, 使它们一样宽. image caption有一个原始宽度200px. 但是用HtmlUnit获得image caption div属性始终是html原始代码中的属性: word-wrap:break-word; width:200px, 请问如何获得被jQuery动态改变的html element属性值. 比如:word-wrap:break-word; width:258px. 谢谢!
------------------------------------------------------------------
HtmlElement imageCaption = testedPage.getElementById("caption_1");
String imageStyle = imageCaption.getAttribute("style");
println("Image Caption Style: " + imageStyle);
------------------------------------------------------------------
------------------------------------------------------------------
<img src="<%=compFile%>" id="image_<%=i%>" class="
<%
if (compIsNeedBorder)
{
%>
imageStyleBorder
<%
}
else
{
%>
imageStyle
<% } %>
"/>
<div id="caption_<%=i%>" class="caption" style="word-wrap:break-word; width: 200px"><%=compText.replaceAll("<p>", "").replaceAll("</p>", "").replaceAll(" ", " ")%></div>
<script type="text/javascript">
// call function after the image load
function CallFunAfterImgLoad(imgId, callback)
{
jQuery("#" + imgId).load(function(){ callback(); });
//$("#" + imgId).ready(function(){ callback(); });
}
function ImageReadyCallback()
{
var imageWidth = jQuery("#image_<%=i%>").width();
// alert("Image Width: " + imageWidth);
if (0 == imageWidth)
{
//alert ("image width: 0px");
setTimeout(ImageReadyCallback, 100);
return;
}
$("#caption_<%=i%>").width(imageWidth);
}
CallFunAfterImgLoad("image_<%=i%>", ImageReadyCallback);
</script>
------------------------------------------------------------------ |
|