//使用watin测试一些ajax网站,当点击td时,div("appendProdctTreeDiv")将显示一些响应html,但我不知道如何获得这个div innerhtml并点击我想要的链接; 可以通过测试"http://www.google.com/ig"?thanks提前给出一些例子!
------使用watin --------
IE ie = new IE();
....
ie.Element(Find.ById("tree")).Click();
textbox1.text = ie.Div("appendProdctTreeDiv").innerHtml; //这种方式错了;
...
..html代码..
<'TD id = tree onclick = showAppendProductTree()noWrap> tab1 <'/ TD>
....
<'DIV style ="WIDTH:100%; HEIGHT:96%; OVERFLOW:auto"id = appendProdctTreeDiv loaded ="false"> <'/ DIV>
....
function showAppendProductTree(){
showTreeTab(3);
Run Code Online (Sandbox Code Playgroud)
if(document.getElementById("appendProdctTreeDiv").loaded =="false"){
var url ="product!changeAppendProduct.do";
var params = "";
var newProductId = document.getElementById("newProductId").value;
new Ajax.Request(
url,
{
method: 'get',
parameters: params+"&random="+Math.random(),
requestHeaders:["Cache-Control","no-cache"],
onComplete: function(originalRequest){
var message = originalRequest.responseText;
document.getElementById("appendProdctTreeDiv").innerHTML= message;
document.getElementById("appendProdctTreeDiv").loaded = "true";
synAppendTree();
document.getElementById("waitLoadAppendProd").style.display = "none";
document.getElementById("searchDiv").style.display = "block";
}
});
}
Run Code Online (Sandbox Code Playgroud)
}
function showTreeTab(tabId){
document.getElementById("treeDiv").style.display ="block";
for(var i=1;i<=3;i++){
if(i==tabId){
document.getElementById("tree"+i).style.display = "block";
}
else{
document.getElementById("tree"+i).style.display = "none";
}
}
Run Code Online (Sandbox Code Playgroud)
}
我认为您有几种方法可以等待响应.选项1:
首先,WatiN默认等待30秒,以便在页面上显示元素.因此,如果您知道要单击的链接的ID或文本,我希望以下代码可以正常工作:
ie.Div("appendProdctTreeDiv").链接(Find.ByText("链接文本")).Click();
如果没有,这里是选项2:
在触发ajax调用的脚本中,在oncomplete回调函数中,div的loaded属性设置为true(在你包含的html中为false).您可以在等到调用之前使用它,然后获取innerhtml或单击要单击的链接:
ie.Div("appendProdctTreeDiv").WaitUntil("loaded","true");
HTH,Jeroen