Esempio n. 1
0
 public Object fireEventWithJS(WebLocator el, String eventName) {
   String script =
       "if(document.createEvent){"
           + "var evObj = document.createEvent('MouseEvents');\n"
           + "evObj.initEvent('"
           + eventName
           + "', true, true);\n"
           + "return fireOnThis.dispatchEvent(evObj);\n"
           + "} else if(document.createEventObject) {"
           + "return fireOnThis.fireEvent('on"
           + eventName
           + "');"
           + "}";
   String id = getAttributeId(el);
   String cls;
   if (!"".equals(id)) {
     script = "var fireOnThis = document.getElementById('" + id + "');\n" + script;
   } else if (!"".equals(cls = getAttribute(el, "class"))) {
     script = "var fireOnThis = document.getElementsByClassName('" + cls + "')[0];\n" + script;
   } else {
     script =
         "var fireOnThis = document.evaluate(\""
             + el.getXPath()
             + "\", document, null, XPathResult.ANY_TYPE, null).iterateNext();\n"
             + "var evObj = document.createEvent('MouseEvents');\n"
             + "evObj.initEvent( '"
             + eventName
             + "', true, true );\n"
             + "return fireOnThis.dispatchEvent(evObj);";
   }
   return executeScript(script);
 }
Esempio n. 2
0
 private String getSelector(WebLocator el) {
   String css = el.getCssSelector();
   return StringUtils.isEmpty(css) ? el.getXPath() : css;
 }