Ask a Question

not able to use Drag method

SOLVED
nitingambhir88
Occasional Contributor

not able to use Drag method

Hi,

 

I am trying to drag and drop an item from one panel to another. When i record and play the script, it works fine. But when i try to use the Drag method in my script (using javascript), it says Drag is not a function. What is possible wrong here ?

 

Record script - 

let page = Aliases.pageShoppingPortal;

page.panel.Drag(134, 23, 26, 182);

 

Javascript - 

let memberdrag = page.contentDocument.getElementsByClassName("name cdk-drag");

memberdrag.item(1).Drag(134, 23, 26, 182);

18 REPLIES 18

Hi,

 

As per documentation, the Depth parameter for the .Find() method (the third one ) must be positive integer.

Try to change -1 to some big value.

 

Quote from the documentation:

"Depth

An integer number that specifies the level of objects where Find will search for the desired object. If Depth is less than or equal to 0, it means that the method will search only in testObj. If Depth is 1 (default), Find will search in testObj and its child objects, if Depth is 2, Find will search in testObj and its child and grandchild objects, and so on. To search in the whole testObj hierarchy, use a Depth value that is greater than the number of child levels in the hierarchy, for example, 20000."

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
nitingambhir88
Occasional Contributor

Hey Alex,

 

Yeah ! i tried increasing the depth. That ways, i don't get the invalid parameter error as before.

But, still it is not able to find memberdragFrom and memberdragTo. It says - object cannot be found..

 

Is their any other approach i can follow ?

 

Thanks for your patience.

HI,

 

That ways, i don't get the invalid parameter error as before.

Great.

 

> It says - object cannot be found

Can you provide your code? What recognition parameters do you use?

Mine were provided as an illustration only. You need to investigate actual objects in the Object Browser, choose those that uniquely and stably can identify the objects that you need and use their names and values as the recognition parameters.

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
nitingambhir88
Occasional Contributor

This is the code I am using --- 

 

function Drag_Smartbear(){

let page = Sys.Browser("*").Page("*");


memberdragFrom = page.Find(new Array("class", "index"), new Array("name cdk-drag", 1), 20000);
memberdragTo = page.Find(new Array("class", "index"), new Array("*dragHere*", 2), 20000);

Log.Message(memberdragFrom)
Log.Message(memberdragTo)


if (!(memberdragFrom.Exists && memberdragTo.Exists)){

Log.Message("cannot be dragged")
}else {
Log.Message("Yay ! cann be dragged")
}

 

let toX = memberdragFrom.Left - memberdragTo.Left +memberdragTo.Width / 2;
Log.Message(toX);

let toY = memberdragFrom.Top - memberdragTo.Top +memberdragTo.Height / 2;
Log.Message(toY);

memberdragFrom.Drag (memberdragFrom.Width / 2, memberdragFrom.Height / 2, toX, toY, skNoShift);

 

}

> memberdragFrom = page.Find(new Array("class", "index"), new Array("name cdk-drag", 1), 20000);
> memberdragTo = page.Find(new Array("class", "index"), new Array("*dragHere*", 2), 20000);

Have you checked that the class name of the first sought for element is exactly "name cdk-drag" and that the class name of the second element contains the text "dragHere" ?

Also, does the value of the index property for the first element equals to one and the value of the index property for the second element equals to two?

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
nitingambhir88
Occasional Contributor

Yes Alex. Both class names and index are correct. I have re-verified.

 

function test(){
    
  let page = Sys.Browser("*").Page("*");
  let dragfro = page.contentDocument.getElementsByClassName("name cdk-drag");
    Log.Message(dragfro.length);
    for (let i = 0; i < dragfro.length; i++){
      p = dragfro.item(i).innerText;
    Log.Message(p)
  }

  }

 

Hi,

 

What about the parameters for memberdragTo ?

What line of your code throws the error? What is exact text of the error and what is the content of the corresponding Details log pane?

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
nitingambhir88
Occasional Contributor

 

Hi Alex,

I have verified for memberdragTo  too.. It is fine.

 

The error is thrown at this line : 

let toX = memberdragFrom.Left - memberdragTo.Left +memberdragTo.Width / 2;

 

and the error says - 

You are trying to call the "Left" method or property of an object that does not exist.
 
So, it clearly depicts that test complete is not able to recognize these two-
memberdragFrom = page.Find(new Array("class", "index"), new Array("name cdk-drag", 1), 20000);
memberdragTo = page.Find(new Array("class", "index"), new Array("*dragHere*", 2), 20000);

 

 

nitingambhir88_0-1599460599500.png

 

nitingambhir88_1-1599460665928.png

 

Hi,

 

So, it clearly depicts that test complete is not able to recognize

The error message means not that TestComplete cannot recognize, but that TestComplete cannot find web element that match provided search criteria.

You must examine the elements that you need to find in the Object Browser and identify a set of stable and unique properties that make it possible to find the elements that you are looking for.

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
cancel
Showing results for 
Search instead for 
Did you mean: