Tech Me More

To quench our thirst of sharing knowledge about our day to day experience & solution to techincal problems we face in our projects.

Advertise with us !
Send us an email at

Monday, August 29, 2016

How to drag and drop an element to location specified by X, Y coordinate using selenium

Drag and drop is now common functionality across many web applications for interactive user interface and easy upload. 

To automate drag and drop in your automation test script, selenium provides a class called Actions for interactive actions.

1. Launch
2. Drag and release the element an X=250 and Y= 10 Pixels.

To automate the above scenario using Selenium Webdriver , we would need to use dragAndHold(WebElement element) function of selenium library.


package seleniumInteractive;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public class DragAndDrop {

	static {
		System.setProperty("", "Chrome driver location");

	public static void main(String[] args) {

		WebDriver driver = new ChromeDriver();
		WebElement element = driver.findElement("draggable"));
		Actions action = new Actions(driver);
		action.clickAndHold(element).moveByOffset(250, 10).build().perform();


POC videos:

Please follow our other blog Tester in you for more updates and tutorials of Selenium.

Tuesday, August 9, 2016

Java client to send a file or inputstream to Jersey Restful API

We  often run in the need of Java client where we can send a file to Restful web services. To do so we will need a multi part request and send it to api. Below code demonstrate how to do it using java.

package com.test;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.HttpClientBuilder;

public class JavaClient {

 public int callAPI() throws Exception {
  String url = "http://localhost:8080/testAPI/rest/fileupload";
  HttpClient httpclient = HttpClientBuilder.create()
  HttpPost httppost = new HttpPost(url);
  MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create();
  reqEntity.addBinaryBody("file", new File(""));
  HttpResponse response = httpclient.execute(httppost);
  int statuscode = response.getStatusLine().getStatusCode();
  return statuscode;


You can also use InputStream instead of File if you don't want to send File.

To send the inputstream instead of file please replace the statement  reqEntity.addBinaryBody("file", new File(filePath));

with reqEntity.addBinaryBody("file", fileIPStream); in above code snippet.