Hello all! So, I'm trying to drag and drop elements on a page. The script seems to work ONLY if the elements are visible on the screen. QTP does find the element but when it drags, the page automatically scrolls to the top, and it can't scroll back down to where it needs to drop the dragged element.
So my questions are:
Is there a way to scroll to the specified element and LOCK the scrolling?
Is there a way to stop QTP from jumping to the top of the page when it clicks on something?
Here is some code that I'm using. Ignore the numbers in SS_DragConstantSum, they will become variables later once I'm done testing. Also, both of these elements are not visible until I manually scroll down on the page.
QTP 11.53 P1
Chrome 30
Windows 7
Thank you
An example with CardSort on what happens if I want to put the card into Choice C:
Code centers the screen perfectly, but once the drag is executed...
It scrolls to the top of the page where it can't drop it in Choice C. This only happens when using drag, drop.
I want to avoid using coordinates as much as possible as they can obviously not be reliable depending on the contents of the page.
So my questions are:
Is there a way to scroll to the specified element and LOCK the scrolling?
Is there a way to stop QTP from jumping to the top of the page when it clicks on something?
Here is some code that I'm using. Ignore the numbers in SS_DragConstantSum, they will become variables later once I'm done testing. Also, both of these elements are not visible until I manually scroll down on the page.
QTP 11.53 P1
Chrome 30
Windows 7
Thank you
Code:
'SS_DragFlags
'@Description Drag flags to a specified section in the field
'@Dcoumentation Drag the flag <Name> to the ruler
Public Sub SS_DragFlags(obj, Name)
If obj.WebElement("class:=flag_container", "innerhtml:="&Name).Exist(5) Then
obj.WebElement("class:=flag_container", "innerhtml:="&Name).Drag
obj.WebElement("class:=ruler").Drop
Else
Reporter.ReportEvent micFail, "Flag: "&Name&" | Not found on page", ""
End If
End Sub
RegisterUserFunc "Page" , "SS_DragFlags" , "SS_DragFlags"
'--------------------------------------------------------------------------------------------
'SS_DragCardSort
'@Description Drag cards to a specified section in the field
'@Documentation
Public Sub SS_DragCardSort(obj, CardIndex, DropZoneName)
If obj.Image("class:=ui-draggable", "index:="&CardIndex).Exist(5) Then
obj.Image("class:=ui-draggable", "index:="&CardIndex).Drag
obj.WebElement("class:=OptionRow", "outertext:="&DropZoneName&".*").Drop
Else
Reporter.ReportEvent micFail, "Card Image: "&CardIndex&" or DropZone: "&DropZoneName&" | Not found on page", ""
End If
End Sub
RegisterUserFunc "Page" , "SS_DragCardSort" , "SS_DragCardSort"
'--------------------------------------------------------------------------------------------
An example with CardSort on what happens if I want to put the card into Choice C:
Code centers the screen perfectly, but once the drag is executed...
It scrolls to the top of the page where it can't drop it in Choice C. This only happens when using drag, drop.
I want to avoid using coordinates as much as possible as they can obviously not be reliable depending on the contents of the page.