Those things of QTP -- the final solutions of autocomplete in ajax

1. A case of webedit auto-fill in ajax was used in the recent test. After thinking about it for a long time, I finally came up with a solution:

Set deviceReplay = CreateObject ("Mercury.DeviceReplay")

Browser("xx").Page("xx").WebEdit("xx").Object.focus

deviceReplay.SendString(str)

wait(10)

deviceReplay.PressKey(28)

 

 

 

2. The second method is to use event response and then click the mouse and keyboard. I have operated it myself. This method should be better. There is a forum discussing this issue:

Address: http://www.advancedqtp.com/forums/index.php?action=printpage;topic=5594.0

The code design is as follows:

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

3, the other way adopted;

3.1 First set the operation steps to get the keyboard,

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的问题了。

5. If the above solutions can't solve your problem, you can try a solution, the original web page address:

http://forums.testleaf.com/showthread.php?tid=633&pid=1324&language=settings

 

Arranged as follows:

Method 1: GetSuggestedOptionsArr (EditObj, PageObj, PartialText)

方法二:VerifyOptionsNumber(EditObj,PageObj, PartialText, ExpectedNumber)

方法三:IsInSuggestions(EditObj,PageObj, PartialText, SuggestedText)

方法四:SelectSuggestedOption(EditObj,PageObj, PartialText, SuggestedText)

Method 5: 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, completely rely on the way of simulating the operation of the keyboard:

Address: http://www.slideshare.net/Sampetruda/514785qtpoptionsetupdoc

7. The most quintessential is the following address, which contains all the methods of using DOM and some commonly used functions. It can be said that this is the master's experience code.

Reprinted in: https://www.cnblogs.com/alterhu/archive/2011/12/29/2306781.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324171788&siteId=291194637