How to handle WebDriverException: Element is not clickable at point using java

Some case the element position is not fixed and we want to do some action like click button on that particular element then result an error as 'Exception in thread "main" org.openqa.selenium.WebDriverException: Element is not clickable at point (xx, yy). Other element would receive the click:'. This happens when the element is loaded into the DOM, but the position is not fixed on the UI. There can be some other divs or images or ads that are not loaded completely.

The different workable solutions provided below.
 1. Maximize browser window
 driver.manage().window().maximize();

 2. The page is getting refreshed before clicking on element.

 3. Scroll to element using Keys
driver.findElement(By.id("ID of the element")).sendKeys(Keys.PAGE_DOWN); 
 or
driver.findElement(By.id("ID of the element")).sendKeys(Keys.PAGE_UP);

4. Click on element using  Actions Class
WebElement element = driver.findElement(By.id("login-button"));
Actions action = new Actions(driver);
action.moveToElement(element).click().perform();


5. Page scroll up or down using JavaScriptExecutor
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(250, 0)"); // if the element is on top.
jse.executeScript("scroll(0, 250)"); // if the element is on bottom. 


6. Page move particular X or Y position using JavaScriptExecutor if element is not visible
 WebElement element = driver.findElement(By.id("login-button"));
JavascriptExecutor jse =(JavascriptExecutor)driver;
jse.executeScript("window.scrollTo(0,"element.getLocation().x+")");
element.click();

or
WebElement element = driver.findElement(By.id("login-button"));
JavascriptExecutor jse =(JavascriptExecutor)driver;
jse.executeScript("window.scrollTo(0,"element.getLocation().y+")");
element.click();

or
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView()", driver.findElement(By.id("login-button"));


7.Element is not present at the time of execution. Use WebDriverWait to until the element is present.
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.id("ID of the element")));

How can handle unexpected alert exception in Selenium Webdriver using java

 import java.util.concurrent.TimeUnit;  
 import org.openqa.selenium.Alert;  
 import org.openqa.selenium.NoAlertPresentException;  
 import org.openqa.selenium.UnhandledAlertException;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 public class Unexpectedalert {  
   public static void main(String[] args) {  
     WebDriver driver;  
     // creat firefox driver object    
     driver = new FirefoxDriver();  
     //Maximize browser window    
     driver.manage().window().maximize();  
     //Go to URL    
     driver.get("http://localhost:80/ideascalechallenge");  
     //Set timeout   
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

 
 // handle Alert Exception  
     try {  
 // trigger unexpected alter event  
       driver.get("http://localhost:80/ideascalechallenge/a/idea?templateId=0");  
     } catch (UnhandledAlertException f) {  
       try {  
         Alert alert = driver.switchTo().alert();  
         String alertText = alert.getText();  
         System.out.println("Alert data: " + alertText);  
         alert.accept();  
         //or  depend event
         // alert.dismiss();  
       } catch (NoAlertPresentException e) {  
         e.printStackTrace();  
       }  
     }
  
   }  
 }  

How to send REST api get and post request to server and get response from server in java

REST API Get request
 import java.io.*;  
 import java.net.HttpURLConnection;  
 import java.net.MalformedURLException;  
 import java.net.URL;  
 public class Restapigetrequest {  
   public void requestresponse() {  
     String output = "";  
     String requesturl="http://httpbin.org/get";  
     try {  
       // sent get request to sever  
       URL url = new URL(requesturl);  
       HttpURLConnection conn = (HttpURLConnection) url.openConnection();  
 /*  
      // Add header if need  
       conn.setRequestMethod("GET");  
       conn.setRequestProperty("Content-Type", "application/json");  
       conn.setRequestProperty("token", "da6e387d-8abc-4f88-bf21-ad37deff042e");  
  */  
       // get response from server and print response  
       if (conn.getResponseCode() != 200) {  
         System.out.println(requesturl + " -> Fail " + conn.getResponseCode());  
       } else {  
         BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));  
         while ((output = br.readLine()) != null) {  
           System.out.println(output);  
         }  
         conn.disconnect();  
       }  
     } catch (MalformedURLException e) {  
       e.printStackTrace();  
     } catch (IOException e) {  
       e.printStackTrace();  
     }  
   }  
   public static void main(String[] a) throws IOException {  
     Restapigetrequest at = new Restapigetrequest();  
     at.requestresponse();  
   }  
 }  
Output:
REST API POST request
 import java.io.BufferedReader;  
 import java.io.InputStreamReader;  
 import org.apache.http.HttpResponse;  
 import org.apache.http.client.HttpClient;  
 import org.apache.http.client.methods.HttpPost;  
 import org.apache.http.entity.StringEntity;  
 import org.apache.http.impl.client.DefaultHttpClient;  
 import org.json.simple.JSONArray;  
 import org.json.simple.JSONObject;  
 public class Restapipostrequest {  
   // Generate json string  
   public static String jsonString() {  
  /*  
   {  
   "text": "Generally, these two terms,  
   "title": "test-450",  
   "Id":4869  
  }  
  */  
     JSONObject obj1 = new JSONObject();  
     obj1.put("text", "Generally, these two terms");  
     obj1.put("title", "Idea created by script");  
     obj1.put("Id", 82);  
     System.out.println(obj1.toJSONString());  
     return obj1.toJSONString();  
   }  
   public static void find_contact() {  
     HttpClient httpClient = new DefaultHttpClient();  
     String postcall ="http://httpbin.org/post";  
     try {  
       //you will need api key here!!  
       HttpPost request = new HttpPost(postcall);  
 /*  
                // Add header if need  
       request.addHeader("Content-Type", "application/json");  
       request.addHeader("api_token", "68c93d98-4ce2-4d5b-8a8c-cad25e0ab113");  
       // Add json input if need  
       StringEntity params = new StringEntity(jsonString());  
       request.setEntity(params);  
 */  
       HttpResponse response = httpClient.execute(request);  
       BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));  
       String result = "";  
       String line;  
       while ((line = rd.readLine()) != null) {  
         result += line;  
       }  
       System.out.println(result);  
       rd.close();  
       System.out.println("status:" + response.getStatusLine());  
     } catch (Exception e) {  
       e.printStackTrace();  
     }  
   }  
   public static void main(String args[]) {  
     find_contact();  
   }  
 }