QTP的那些事--ajax中的autocomplete的最终几种解决方案
2011-12-29 23:15
225 查看
1,最近测试中使用到了ajax的一个webedit自动填充的案例,想了好久,终于想到了一个解决的方案:
Set deviceReplay = CreateObject ("Mercury.DeviceReplay") Browser("xx").Page("xx").WebEdit("xx").Object.focus deviceReplay.SendString(str) wait(10) deviceReplay.PressKey(28)
2,第二种方法采用的是事件响应然后再敲击鼠标键盘,本人自己操作过,这个方法应该是比较好的,有一个论坛讨论了这个问题:
地址:http://www.advancedqtp.com/forums/index.php?action=printpage;topic=5594.0
代码设计如下:
dim str="s"
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
3,采用的另外的方式;
3.1首先设置获得键盘的操作步骤,
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
5,如果以上的方案还不能够解决你的问题,可以尝试一下的一种方案,原始网页地址:
http://forums.testleaf.com/showthread.php?tid=633&pid=1324&language=settings
整理如下:
方法一:GetSuggestedOptionsArr(EditObj, PageObj, PartialText)
方法二:VerifyOptionsNumber(EditObj,PageObj, PartialText, ExpectedNumber)
方法三:IsInSuggestions(EditObj,PageObj, PartialText, SuggestedText)
方法四:SelectSuggestedOption(EditObj,PageObj, PartialText, SuggestedText)
方法五:TypeStringFromFirstToLast(EditObj, sText)
The GetSuggestedOptionsArr function simulates the "Auto Complete" behavior by setting a partial value to the search field and triggering the suggestion values retrieval by firing the "onkeyup" event. The Page.ChildObjects method is then used to get a collection of the returned values using a predefined description that uniquely identifies them:
set desc = Description.Create
desc("class").value = "cAutoComplete"
desc("micclass").value = "WebElement"
desc("html tag").value = "SPAN"
After the description is defined, it is used to capture a collection of the suggested possible values:
Set options = Browser("BrowserName").Page("PageName").ChildObjects (desc)
Example:
Create a reference to the Page object that contains the search edit field.
Set PageObj = Browser("Google").Page("Google")
Get an array with the possible search values
Dict = Browser("Google").Page("Google").WebEdit("q").GetSuggestedOptionsArr(PageObj,"a")
msgbox "The array contains " & UBound(Dict) & " suggested search strings."
Verify 10 suggestions were presented
result= Browser("Google").Page("Google").WebEdit("q").VerifyOptionsNumber(PageObj,"a",10)
msgbox "There are 10 suggested search strings: " & result
Check that "aol" is one of the returned suggested search values
bIsInSugg = Browser("Google").Page("Google").WebEdit("q").IsInSuggestions(PageObj,"a", "aol ")
msgbox "The value aol is in the suggested search strings: " & bIsInSugg
Get a vbNewLine delimited string of the suggested search options
txt = Browser("Google").Page("Google").WebEdit("q").GetSuggestedOptions(PageObj,"ca")
MsgBox txt
Enter the ab string character by character
Browser("Google").Page("Google").WebEdit("q").TypeStringFromFirstToLast "ab"
wait 2
6,完全靠模拟键盘的操作的方式:
地址:http://www.slideshare.net/Sampetruda/514785qtpoptionsetupdoc
7。最精华就是下面的这个地址,里面有所有的有关DOM的使用方法,及其常用的一些函数,可以说,这个是大师的经验代码啊。
Set deviceReplay = CreateObject ("Mercury.DeviceReplay") Browser("xx").Page("xx").WebEdit("xx").Object.focus deviceReplay.SendString(str) wait(10) deviceReplay.PressKey(28)
2,第二种方法采用的是事件响应然后再敲击鼠标键盘,本人自己操作过,这个方法应该是比较好的,有一个论坛讨论了这个问题:
地址:http://www.advancedqtp.com/forums/index.php?action=printpage;topic=5594.0
代码设计如下:
dim str="s"
Set WshShell = CreateObject("WScript.Shell") Browser("testapp").Page("testapp").Frame("mIfm-3").WebEdit("dispatchOpName").Set str Browser("testapp").Page("testapp").Frame("mIfm-3").WebEdit("dispatchOpName").FireEvent "onclick" 'This simulate the mouse click event after value is set WshShell.SendKeys "{Down}" 'This displays the drop down list box 'wait 2 WshShell.SendKeys "{Down}" 'This hover over the first element in the list 'wait 2 WshShell.SendKeys "~" 'This selects the hovered element
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
3,采用的另外的方式;
3.1首先设置获得键盘的操作步骤,
Setting.WebPackage("ReplayType") = 2 'enable mouse operations Browser(X).Page(Y).WebEdit(Z).Set "ann"
Setting.WebPackage("ReplayType") = 1 'enable keyboard operations
WshShell.SendKeys "{DOWN}" 'To hit the down arrow n times you can use "{DOWN n}" 'To Select element WshShell.SendKeys "~"
4,其他的方式,暂时不写了。不过以上的已经可以解决大家所有的遇到的ajax的autocomplete的问题了。
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
5,如果以上的方案还不能够解决你的问题,可以尝试一下的一种方案,原始网页地址:
http://forums.testleaf.com/showthread.php?tid=633&pid=1324&language=settings
整理如下:
方法一:GetSuggestedOptionsArr(EditObj, PageObj, PartialText)
方法二:VerifyOptionsNumber(EditObj,PageObj, PartialText, ExpectedNumber)
方法三:IsInSuggestions(EditObj,PageObj, PartialText, SuggestedText)
方法四:SelectSuggestedOption(EditObj,PageObj, PartialText, SuggestedText)
方法五:TypeStringFromFirstToLast(EditObj, sText)
The GetSuggestedOptionsArr function simulates the "Auto Complete" behavior by setting a partial value to the search field and triggering the suggestion values retrieval by firing the "onkeyup" event. The Page.ChildObjects method is then used to get a collection of the returned values using a predefined description that uniquely identifies them:
set desc = Description.Create
desc("class").value = "cAutoComplete"
desc("micclass").value = "WebElement"
desc("html tag").value = "SPAN"
After the description is defined, it is used to capture a collection of the suggested possible values:
Set options = Browser("BrowserName").Page("PageName").ChildObjects (desc)
Example:
Create a reference to the Page object that contains the search edit field.
Set PageObj = Browser("Google").Page("Google")
Get an array with the possible search values
Dict = Browser("Google").Page("Google").WebEdit("q").GetSuggestedOptionsArr(PageObj,"a")
msgbox "The array contains " & UBound(Dict) & " suggested search strings."
Verify 10 suggestions were presented
result= Browser("Google").Page("Google").WebEdit("q").VerifyOptionsNumber(PageObj,"a",10)
msgbox "There are 10 suggested search strings: " & result
Check that "aol" is one of the returned suggested search values
bIsInSugg = Browser("Google").Page("Google").WebEdit("q").IsInSuggestions(PageObj,"a", "aol ")
msgbox "The value aol is in the suggested search strings: " & bIsInSugg
Get a vbNewLine delimited string of the suggested search options
txt = Browser("Google").Page("Google").WebEdit("q").GetSuggestedOptions(PageObj,"ca")
MsgBox txt
Enter the ab string character by character
Browser("Google").Page("Google").WebEdit("q").TypeStringFromFirstToLast "ab"
wait 2
6,完全靠模拟键盘的操作的方式:
地址:http://www.slideshare.net/Sampetruda/514785qtpoptionsetupdoc
7。最精华就是下面的这个地址,里面有所有的有关DOM的使用方法,及其常用的一些函数,可以说,这个是大师的经验代码啊。
相关文章推荐
- QTP的那些事--DOM的几种内置的获取对象方法
- Ajax缓存和编码问题的最终解决方案
- ajax跨域和JS的跨域通信(Cross The Site)的几种解决方案
- 关于Win7下QTP的几种问题和解决方案
- QTP的那些事--ajax处理的总结篇(不同情况的处理)
- AJAX中文乱码的几种后台的解决方案
- QTP的那些事--QC远程执行QTP经常出现QTP崩溃现象解决方案
- iframe跨域、ajax跨域和JS跨域通信的几种解决方案
- Ajax 跨域的几种解决方案
- QTP的那些事--QTP测试AJAX时的等待问题(转陈能技老师博客)
- QTP的那些事--用QTP测试Web上的Ajax
- 集群中几种session同步解决方案的比较
- 使用Ajax之后要alert才能执行的解决方案
- 文件系统那些事-第4篇 并行文件系统之开源解决方案Lustre
- ASP.NET 链接 Access 数据库路径问题最终解决方案
- jquery autocomplete插件结合ajax使用
- 实现在线预览PDF的几种解决方案
- 百试不爽的 Ajax向后台传参乱码问题解决方案
- IE不支持getElementsByClassName最终完美解决方案
- PHP Ajax 跨域问题最佳解决方案