Many of the UI draggable elements can be easily draggable from one place to another place over the web page.
In some cases though the web element is associated with draggable properties, they won't respond when we do drag action through our selenium code by using Actions class. Below are few of the scenario, which will help you to drag and drop your draggable web elements over the web page.
The draggable elements can be anything with draggable properties associated with. It could be a table header cell or can be draggable div or a frame or etc. Lets take an example of a source element(from which you will start the drag action) and a destination element(at which you will drop by releasing your mouse) as below:
(1) By using Actions class of Selenium webdriver
Case 1:
Selenium web driver provides Actions class to do drag and drop actions in the web page.
This will work for most of the draggable web elements.
Case 2:
In case of some of the draggable web element the below works very well:
Make sure to call the perform() method at the end like above.
Case 3:
In few website the draggable elements doesn't work with either of the above cases. Then you can try the below:
You can adjust the xOffset and yOffset values(which is 2 in the above example) as per your requirements
Case 4:
This case is very interesting one which will work anyway for all the types of draggable UI elements in the webpage.
In the above code the 2 second wait during the drag and drop action is important. I would suggest use this way only if the above cases are not working for you.
(2) By using Robot class
Case 1:
If any of the above drag and drop actions using selenium doesn't work for you, do the drag and drop using Robot class as below:
In some cases though the web element is associated with draggable properties, they won't respond when we do drag action through our selenium code by using Actions class. Below are few of the scenario, which will help you to drag and drop your draggable web elements over the web page.
The draggable elements can be anything with draggable properties associated with. It could be a table header cell or can be draggable div or a frame or etc. Lets take an example of a source element(from which you will start the drag action) and a destination element(at which you will drop by releasing your mouse) as below:
Case 1:
Selenium web driver provides Actions class to do drag and drop actions in the web page.
Case 2:
In case of some of the draggable web element the below works very well:
Case 3:
In few website the draggable elements doesn't work with either of the above cases. Then you can try the below:
Case 4:
This case is very interesting one which will work anyway for all the types of draggable UI elements in the webpage.
(2) By using Robot class
Case 1:
If any of the above drag and drop actions using selenium doesn't work for you, do the drag and drop using Robot class as below:
cool stuff you have got and you keep update all of us. drag and drop website builder
ReplyDelete