Time for action – creating an Actions chain for dragging and dropping - Selenium

A lot of web applications these days allow users to drag and drop what they want where they want on the page. This is really nice from a usability point of view, but from a testability point it is a nightmare!

We can get around this with actions API.

  1. Open up inteliij and create a new Selenium WebDriver project.

  2. Create a new class and a new test with the following code:

  3. Run the test. You should see this first:

  4. And when it is complete you will see the block go blue:

What just happened?

We have just seen how easy it is to do a drag and drop on the page. We just need to create an Actions object and then create a chain of events. When we have built up the chain we call build(). This puts everything in the right order and when we call perform(), the items are popped out of the queue and run in order.

Let us have a look at doing some slightly more complex chains with the Actions class.

Moving an element to an offset

We can get around this with the actions API.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics