package org.openqa.selenium.qtwebkit;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.remote.internal.JsonToWebElementConverter;

import java.util.Collection;
import java.util.Map;

public class QtWebKitJsonToWebElementConverter extends JsonToWebElementConverter {

  public QtWebKitJsonToWebElementConverter(QtWebKitDriver driver) {
    super(driver);
  }

  public Object apply(Object result) {
    if (result instanceof Collection<?>) {
      Collection<?> results = (Collection<?>) result;
      return Lists.newArrayList(Iterables.transform(results, this));
    }

    if (result instanceof Map<?, ?>) {
      Map<?, ?> resultAsMap = (Map<?, ?>) result;
      if (resultAsMap.containsKey("ELEMENT")) {
        RemoteWebElement element = newRemoteWebElement();
        element.setId(String.valueOf(resultAsMap.get("ELEMENT")));
        element.setFileDetector(driver.getFileDetector());

        RemotePlayer player = newRemotePlayerElement();
        player.setId(String.valueOf(resultAsMap.get("ELEMENT")));
        player.setFileDetector(driver.getFileDetector());
        if(player.getState() != null){
          return player;
        }
        return element;
      } else {
        return Maps.transformValues(resultAsMap, this);
      }
    }

    if (result instanceof Number) {
      if (result instanceof Float || result instanceof Double) {
        return ((Number) result).doubleValue();
      }
      return ((Number) result).longValue();
    }

    return result;
  }


  protected RemotePlayer newRemotePlayerElement() {
    RemotePlayer toReturn = new RemotePlayer();
    toReturn.setParent(driver);
    return toReturn;
  }

}

@@ -156,16 +156,63 @@
 .Maps;%0A%0A
+import org.openqa.selenium.WebDriverException;%0A
 import o
@@ -1264,24 +1264,41 @@
 etector());%0A
+        try%7B%0A    
         if(p
@@ -1330,24 +1330,28 @@
 %7B%0A          
+   
+ 
 return playe
@@ -1357,26 +1357,74 @@
 er;%0A        
+    
 %7D%0A
+        %7D catch (WebDriverException e)%7B%0A    
         retu
@@ -1435,16 +1435,26 @@
 lement;%0A
+        %7D%0A
       %7D 

Correct error in JsonToWebElement converter