/*
Most actions can be performed using the normal augmented driver, but for findElement, the
findElement(s) must be override, so need to create a new object from scratch.
964911
public static RemoteIOSDriver getIOSDriver(RemoteWebDriver driver) {
    if (!(driver.getCommandExecutor() instanceof HttpCommandExecutor)) {
      throw new WebDriverException("ios only supports http commandExecutor.");
    }
    HttpCommandExecutor e = (HttpCommandExecutor) driver.getCommandExecutor();
    RemoteIOSDriver
        attach =
        new AttachRemoteIOSDriver(e.getAddressOfRemoteServer(), driver.getSessionId());
    return attach;
  }
1300720
@Override
    protected void doPerform() {
        WebElement source = isSourceDocumentRoot() ? null : getFirstElement();
        if (offset != null) {
            Point offsetPoint = offset.offset(getSize());
            getActions().moveToElement(source, offsetPoint.x(), offsetPoint.y()).perform();
        } else {
            getActions().moveToElement(source).perform();
        }
    }
194553
private CmsContainerPageElementPanel createElement(
        Element element,
        I_CmsDropContainer dragParent,
        CmsContainerElement elementData) {

        CmsContainerPageElementPanel dragElement = new CmsContainerPageElementPanel(
            element,
            dragParent,
            elementData.getClientId(),
            elementData.getSitePath(),
            elementData.getNoEditReason(),
            elementData.getTitle(),
            elementData.getSubTitle(),
            elementData.getResourceType(),
            elementData.hasSettings(dragParent.getContainerId()),
            elementData.hasViewPermission(),
            elementData.hasWritePermission(),
            elementData.isReleasedAndNotExpired(),
            elementData.isNewEditorDisabled(),
            elementData.hasEditHandler(),
            elementData.getModelGroupId(),
            elementData.isWasModelGroup(),
            elementData.getElementView(),
            elementData.getBigIconClasses());
        dragElement.setCreateNew(elementData.isCreateNew());
        if (m_controller.requiresOptionBar(dragElement, dragParent)) {
            addOptionBar(dragElement);
        }
        if (m_controller.isInlineEditable(dragElement, dragParent)) {
            dragElement.initInlineEditor(m_controller);
        }
        return dragElement;
    }
954748
@Override
    public T visitElement(Element elm, C context) {
        if (elm instanceof IncludeDef) return visitIncludeDef((IncludeDef)elm, context);
        else if (elm instanceof Library) return visitLibrary((Library)elm, context);
        else if (elm instanceof UsingDef) return visitUsingDef((UsingDef)elm, context);
        else return super.visitElement(elm, context);
    }
122469
function createCallback(element,callback) {

    var fn = function(originalEvent) {

      !originalEvent && ( originalEvent = window.event );

      // create a normalized event object
      var event = {
        // keep a ref to the original event object
        originalEvent: originalEvent,
        target: originalEvent.target || originalEvent.srcElement,
        type: "wheel",
        deltaMode: originalEvent.type == "MozMousePixelScroll" ? 0 : 1,
        deltaX: 0,
        delatZ: 0,
        preventDefault: function() {
          originalEvent.preventDefault ?
            originalEvent.preventDefault() :
            originalEvent.returnValue = false;
        }
      };

      // calculate deltaY (and deltaX) according to the event
      if ( support == "mousewheel" ) {
        event.deltaY = - 1/40 * originalEvent.wheelDelta;
        // Webkit also support wheelDeltaX
        originalEvent.wheelDeltaX && ( event.deltaX = - 1/40 * originalEvent.wheelDeltaX );
      } else {
        event.deltaY = originalEvent.detail;
      }

      // it's time to fire the callback
      return callback( event );

    };

    fns.push({
      element: element,
      fn: fn,
    });

    return fn;
  }
973611
function(el) {
            var self = this;

            self.callActions('beforeCacheDom', arguments);

            self.dom.el = el;

            self.callActions('afterCacheDom', arguments);
        }
860604
public static ExpectedCondition<Boolean> invisibilityOfElementLocated(final By locator) {
    return new ExpectedCondition<Boolean>() {
      @Override
      public Boolean apply(WebDriver driver) {
        try {
          return !(driver.findElement(locator).isDisplayed());
        } catch (NoSuchElementException e) {
          // Returns true because the element is not present in DOM. The
          // try block checks if the element is present but is invisible.
          return true;
        } catch (StaleElementReferenceException e) {
          // Returns true because stale element reference implies that element
          // is no longer visible.
          return true;
        }
      }

      @Override
      public String toString() {
        return "element to no longer be visible: " + locator;
      }
    };
  }
1072071
public Actions click(WebElement target) {
    if (isBuildingActions()) {
      action.addAction(new ClickAction(jsonMouse, (Locatable) target));
    }

    return moveInTicks(target, 0, 0).clickInTicks(LEFT);
  }
1299936
function(options) {
  options = options || {};
  var that = this;
  // Either use the provided element or make up a new element
  this.el = options.el || window.document.createElement(options.elementType || 'div');
  this.$el = $(this.el);

  this.dispatchDOMEvents();
}
1360903
protected WebElement findElement(String by, String using, OperaWebElement el) {
    checkNotNull(using, "Cannot find elements when the selector is null");
    assertConnected();

    using = OperaStrings.escapeJsString(using);
    boolean isAvailable;
    Integer id;
    String script;

    if (el == null) {
      // Search the document
      script =
          "return " + OperaAtom.FIND_ELEMENT + "({\"" + by + "\": \"" + using + "\"})";
    } else {
      // Search within an element
      script =
          "return " + OperaAtom.FIND_ELEMENT + "({\"" + by + "\": \"" + using
          + "\"}, locator)";
    }

    if (el == null) {
      id = debugger.getObject(script);
    } else {
      id = debugger.executeScriptOnObject(script, el.getObjectId());
    }

    isAvailable = (id != null);

    if (isAvailable) {
      String error =
          debugger.callFunctionOnObject("return (locator instanceof Error) ? locator.message : ''",
                                        id);
      if (!error.isEmpty()) {
        throw new InvalidSelectorException(error);
      }

      Boolean isStale =
          Boolean.valueOf(debugger.callFunctionOnObject("locator.parentNode == undefined", id));

      if (isStale) {
        throw new StaleElementReferenceException("This element is no longer part of DOM");
      }

      return new OperaWebElement(this, id);
    } else {
      throw new NoSuchElementException("Cannot find element(s) with " + by);
    }
  }
811209
public CmsContainerPageElementPanel createElement(
        CmsContainerElementData containerElement,
        I_CmsDropContainer container,
        boolean isNew)
    throws Exception {

        if (containerElement.isGroupContainer() || containerElement.isInheritContainer()) {
            List<CmsContainerElementData> subElements = new ArrayList<CmsContainerElementData>();
            for (String subId : containerElement.getSubItems()) {
                CmsContainerElementData element = m_controller.getCachedElement(subId);
                if (element != null) {
                    subElements.add(element);
                } else {
                    CmsDebugLog.getInstance().printLine("Cached element not found");
                }
            }
            return createGroupcontainerElement(containerElement, subElements, container);
        }
        Element element = CmsDomUtil.createElement(containerElement.getContents().get(container.getContainerId()));
        // ensure any embedded flash players are set opaque so UI elements may be placed above them
        CmsDomUtil.fixFlashZindex(element);
        if (isNew) {
            CmsContentEditor.replaceResourceIds(
                element,
                CmsUUID.getNullUUID().toString(),
                CmsContainerpageController.getServerId(containerElement.getClientId()));
        }

        CmsContainerPageElementPanel result = createElement(element, container, containerElement);
        if (!CmsContainerpageController.get().shouldShowInContext(containerElement)) {
            result.getElement().getStyle().setDisplay(Style.Display.NONE);
            result.addStyleName(CmsTemplateContextInfo.DUMMY_ELEMENT_MARKER);
        }
        return result;
    }
1325755
function(el) {
		var self = this,
			$el = $(el);

		if ($el.length > 1) {
			$el.each(function() {
				self.addElement(this);
			});
		} else if ($el.length === 0) {
			throw new Error("Invalid element!");
		}

		if (this.$el.closest($el).length) {
			throw new Error("Element is a child of this view. This is only for unrelated elements");
		}
		if ($el.closest(this.$el).length) {
			throw new Error("Element is an ancestor of this view! Reconsider how you're using this view.");
		}

		// normalize
		el = $el.get(0);

		if (!this._trackedElements) {
			this._trackedElements = [];
		}
		_(this._trackedElements).each(function(otherEl) {
			var $otherEl = $(otherEl);

			if ($otherEl.closest($el).length) {
				throw new Error("Element is a child of another tracked element. This will cause problems.");
			}
			if ($el.closest($otherEl).length) {
				throw new Error("Element is an ancestor of another tracked element. This will cause problems.");
			}
		});
		this._trackedElements.push(el);
	}
838837
function FinderBuilder(newDocument) {
// private
    var doc = newDocument;

    function buildIdFinder(e) {
        if (e.id) {
            var id = e.id;

            return (function(targetDoc) {
                return targetDoc.getElementById(id);
            });
        }

        return null;
    }

    function buildTagNameFinder(e) {
        var elements = doc.getElementsByTagName(e.tagName);

        for (var i = 0, n = elements.length; i < n; ++i) {
            if (elements[i] === e) {
                // both the descendant axis and getElementsByTagName() should
                // return elements in document order; hence the following index
                // operation is possible
                return (function(targetDoc) {
                    return targetDoc.getElementsByTagName(e.tagName)[i];
                });
            }
        }

        return null;
    }

// public
    this.setDocument = function(newDocument) {
        doc = newDocument;
        return this;
    };

    this.build = function(e) {
        return (
            buildIdFinder(e) ||
            buildTagNameFinder(e)
        );
    };
}
1374470
public WebElement find() {
		checkState(webDriver != null, "No WebDriver specified.");
		checkState(by != null, "No By instance for locating elements specified.");

		if (!noLogging) {
			log.info(toString());
		}

		WebElement element;

		if (timeoutSeconds > 0L) {
			WebDriverWait wait = createWebDriverWait();
			element = wait.until(new Function<WebDriver, WebElement>() {
				@Override
				public WebElement apply(final WebDriver input) {
					WebElement el = input.findElement(by);
					checkElement(el);
					if (condition != null && !condition.apply(el)) {
						throw new WebElementException(String.format("Condition not met for element %s: %s", el, condition));
					}
					return el;
				}

				@Override
				public String toString() {
					return WebElementFinder.this.toString();
				}
			});
		} else {
			element = webDriver.findElement(by);
			checkElement(element);
			if (condition != null && !condition.apply(element)) {
				throw new WebElementException(String.format("Condition not met for element %s: %s", element, condition));
			}
		}

		return element;
	}
198169
function() {
      element.find('a, button').mousemove(function(e) {
        if (buttonPickerEnabled) {
          if (e.target !== buttonToPickElement) {
            buttonToPickCounter = 0;
            buttonToPickElement = e.target;
          }

          buttonToPickCounter += 1;
          if (buttonToPickCounter > 50) {
            element.find('a, button').css('border', '');
            $(e.target).css('border', 'solid 2px green');

            var createSelector = function(element) {
              if (element.attr('id')) {
                return '#' + element.attr('id');
              } else {
                var classes = element.attr('class').split(/\s/);
                return classes.map(function(x) {
                  return '.' + x;
                }).join('');
              }
            };

            if (buttonToPick === 'undo') {
              editor.find('.kelmu-editor-undo-button').val(createSelector($(e.target)));
            } else if (buttonToPick === 'redo') {
              editor.find('.kelmu-editor-redo-button').val(createSelector($(e.target)));
            } else if (buttonToPick === 'step') {
              editor.find('.kelmu-editor-step-button').val(createSelector($(e.target)));
            } else if (buttonToPick === 'begin') {
              editor.find('.kelmu-editor-begin-button').val(createSelector($(e.target)));
            }

            buttonPickerEnabled = false;
            buttonToPickCounter = 0;

            setTimeout(function() {
              element.find('a, button').css('border', '');
            }, 5000);

          }
        }
      });
      buttonPickerCreated = true;
    }
551025
function() {
      return elementArrayFinder.getWebElements().then(function(webElements) {
        if (webElements.length === 0) {
          throw new webdriver.error.Error(
              webdriver.error.ErrorCode.NO_SUCH_ELEMENT,
              'No element found using locator: ' +
                  elementArrayFinder.locator_.toString());
        } else {
          if (webElements.length > 1) {
            console.log('warning: more than one element found for locator ' +
                elementArrayFinder.locator_.toString() +
                ' - you may need to be more specific');
          }
          return [webElements[0]];
        }
      });
    }
119850
function HtmlUnitDriver(
  desiredCapabilitiesOrEnableJavascript
  ) {
  var instance;
  var first = desiredCapabilitiesOrEnableJavascript;
  var len = arguments.length;

  if (!len) {
    instance = new Class();
  } else if (len === 1) {
    if (assert(first).extends(Capabilities).isValid) {
      instance = new Class(first._instance);
    } else if (assert.isBool(first)) {
      instance = new Class(first);
    } else {
      throw new Error(
        'The first argument must be an instance of Capabilities or a boolean.'
       );
    }
  } else {
    throw new Error('The wrong number of arguments was given.');
  }

  addFinalProp(this, '_instance', instance);
}