The click function and wait for one of the expected {@link Object} items to load.

@param expected
parameters in the form of an element locator {@link String}, a {@link WebPage}, or an
{@link AbstractElement}
@return the first object that was matched
166789
public Object clickAndExpectOneOf(final Object... expected) {
        dispatcher.beforeClick(this, expected);

        getElement().click();
        if (Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.ENABLE_GUI_LOGGING))) {
            logUIAction(UIActions.CLICKED);
        }

        // If there are no expected objects, then it means user wants this method
        // to behave as a clickonly. So lets skip processing of alerts and leave
        // that to the user.
        if (expected == null || expected.length == 0) {
            return null;
        }
        if (parent != null) {
            WebDriverWaitUtils.waitUntilPageIsLoaded(parent.getCurrentPage());
        }
        validatePresenceOfAlert();

        long timeout = Grid.getExecutionTimeoutValue() / 1000;

        try {

            WebDriverWait wait = new WebDriverWait(Grid.driver(), timeout);
            wait.ignoring(NoSuchElementException.class);
            wait.ignoring(PageValidationException.class);

            Object expectedObj = wait.ignoring(ExpectOneOfException.class).until(new Function<WebDriver, Object>() {

                // find the first object that is matched and return it
                @Override
                public Object apply(WebDriver webDriver) {
                    StringBuilder sb = new StringBuilder();

                    int i = 1;
                    for (Object expect : expected) {
                        try {
                            if (expect instanceof AbstractElement) {
                                AbstractElement element = (AbstractElement) expect;
                                if (HtmlElementUtils.locateElement(element.getLocator()) != null) {
                                    return expect;
                                }
                            } else if (expect instanceof String) {
                                String s = (String) expect;
                                if (HtmlElementUtils.locateElement(s) != null) {
                                    return expect;
                                }
                            } else if (expect instanceof WebPage) {
                                WebPage w = (WebPage) expect;

                                w.validatePage();
                                return expect;
                            }
                        } catch (NoSuchElementException | PageValidationException e) { // NOSONAR
                            sb.append("\n\tObject " + i + ": " + expect.getClass().getSimpleName() + "\n");
                            sb.append("\t" + ExceptionUtils.getRootCauseMessage(e) + "\n");
                            sb.append("\t\t" + StringUtils.substringBetween(ExceptionUtils.getStackTrace(e), "\n"));
                        }
                        i++;
                    }

                    throw new ExpectOneOfException(sb.toString());
                }
            });

            return expectedObj;

        } finally {
            // Attempt at taking screenshots even when there are time-outs triggered from the wait* methods.
            processScreenShot();

            dispatcher.afterClick(this, expected);
        }
    }
925927
function waitelem (self, selector, done) {
  let elementPresent
  eval('elementPresent = function() {' + // eslint-disable-line
    `  var element = document.querySelector('${selector}');` +
    '  if (!element) { return null }' +
    '  for (let key in element) {' +
    '    if (key.startsWith(\'__reactInternalInstance$\')) {' +
    '      const compInternals = element[key]._currentElement;' +
    '      const compWrapper = compInternals._owner;' +
    '      const {props, state, context} = compWrapper._instance;' +
    '      return {props, state, context}' +
    '    }' +
    '  }' +
    '  return null;' +
    '}')
  waitfn.apply(this, [self, elementPresent, done])
}
45111
public Optional<MethodParameter> getParameter(String name) {

		Assert.hasText(name, "Parameter name must not be null!");

		return getParameters().stream() //
				.filter(it -> name.equals(it.getParameterName())) //
				.findFirst();
	}
1239518
private String getFirstCallParam() {

        final String param = parseOptionalStringValue(XML_ELEMENT_RELOADED_PARAM);
        if (param == null) {
            return DEFAULT_RELOADED_PARAM;
        } else {
            return param;
        }
    }
1323893
def click(self, locator, params=None, timeout=None):
        
        self._click(locator, params, timeout)
347371
@BeforeSuite(alwaysRun=true)
	@Parameters(value={"parameters"})
	public static void startSelenium(String parameters)
	{
		parametersMap = parameterScanner(parameters);
		
		parametersInfo();
		
		String 	browserName = parametersMap.get("browser"),
				profile = parametersMap.get("profile"),
				chromeDriverBin = parametersMap.get("chromeDriverBin"),
				ieDriverBin = parametersMap.get("ieDriverBin"),
				chromeBin = parametersMap.get("chromeBin"),
				languages = parametersMap.get("languages");
				
		if(browserName == null){
			throw new IllegalArgumentException(String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL,"browser"));
		}
		
		if(driver == null) {
			if(BrowsersList.FIREFOX.equalsString(browserName)){
				FirefoxProfile fp = new FirefoxProfile();
				fp.setPreference("dom.max_script_run_time", 0);
				fp.setPreference("dom.max_chrome_script_run_time", 0);
				if(profile != null && !profile.isEmpty()){
					fp.setPreference("webdriver.firefox.profile", profile);
				}
				if(languages != null && !languages.isEmpty()){
					fp.setPreference("intl.accept_languages", languages);
				}
				driver = new WebDriverAdapter(new FirefoxDriver(fp));
			}
			else if(BrowsersList.CHROME.equalsString(browserName)) {
				
				if(chromeBin == null){
					throw new IllegalArgumentException(String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL,"chromeBin"));
				}
				
				
				// Optional, if not specified, WebDriver will search your path for chromedriver 
				// in the system environment. (OBS: To evade problems, webdriver.chrome.driver MUST have a value.
				if(System.getProperty("webdriver.chrome.driver") == null || System.getProperty("webdriver.chrome.driver").isEmpty()){
					if(chromeDriverBin == null){
						throw new IllegalArgumentException(String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL,"chromeDriverBin"));
					}
					System.setProperty("webdriver.chrome.driver", chromeDriverBin);	
				}
				
				ChromeOptions co = new ChromeOptions();
				// Get the chrome binary directory path from System Envionment.
				co.setBinary(new File(chromeBin));
				driver = new WebDriverAdapter(new ChromeDriver(co));
			}
			else if(BrowsersList.IE.equalsString(browserName))
			{
				if(ieDriverBin == null){
						throw new IllegalArgumentException(String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL,"ieDriverBin"));
				}
				System.setProperty("webdriver.ie.driver", ieDriverBin);	
				driver = new WebDriverAdapter(new InternetExplorerDriver());
			}
			else if(BrowsersList.HTML_UNIT.equalsString(browserName)){
				driver = new HtmlUnitDriver(true);
			}
			else {
				throw new IllegalArgumentException(ErrorMessages.ERROR_BROWSER_INVALID);
			}
		}
		/* Sets to all driver methods the global timeout of 1 second. 
		 * To tests, Timeouts must be specified on the components.
		 */
		SeleniumController.driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
		SeleniumController.builder = new SeleniumBuilder(driver);
		SeleniumController.browser = new SeleniumBrowser();
		ListenerGateway.setWebDriver(driver);
		ListenerGateway.setParameters(parametersMap);
	}
1080433
@Override
	public void click() throws WidgetException {
		try {
		   final WebElement webElement = getWebElement();

		        if (!getGUIDriver().isJavascriptClickMode()) {
		            synchronized (InteractiveElement.class) {
		                getGUIDriver().focus();
		                highlight( HIGHLIGHT_MODES.PUT);
		                webElement.click();
		            }
		        } else {
                    highlight( HIGHLIGHT_MODES.PUT);
                    try {
                        eval("arguments[0].click();");
                    } catch (WidgetException we) {
                        throw new RuntimeException(we);
                    }
		        }

		        getGUIDriver().selectLastFrame();
		} catch (Exception e) {
			throw new WidgetException("Error while clicking element",
					getByLocator(), e);
		}
	}
149623
public static ExpectedCondition<Boolean> textToBeEqualsToExpectedValue(final By locator, final String value) {
        return new ExpectedCondition<Boolean>() {
            /**
             * {@inheritDoc}
             */
            @Override
            public Boolean apply(@Nullable WebDriver driver) {
                try {
                    final WebElement element = driver.findElement(locator);
                    if (element != null && value != null) {
                        return !((element.getAttribute(VALUE) == null || !value.equals(element.getAttribute(VALUE).trim())) && !value.equals(element.getText().replaceAll("\n", "")));
                    }
                } catch (final Exception e) {
                }
                return false;
            }
        };
    }
599237
public static By callback(final Function<SearchContext, List<WebElement>> callback) {
		if (callback == null)
			throw new IllegalArgumentException("Cannot find elements when the callback is null");

		return new ByCallback(callback);
	}
1258927
public static void waitUntilElementIsPresent(final String elementLocator) {
        logger.entering(elementLocator);
        By by = HtmlElementUtils.resolveByType(elementLocator);
        ExpectedCondition<WebElement> condition = ExpectedConditions.presenceOfElementLocated(by);
        waitForCondition(condition);
        logger.exiting();
    }
901936
public static ExpectedCondition<WebElement> elementToBeClickable(final By locator) {
    return new ExpectedCondition<WebElement>() {
      @Override
      public WebElement apply(WebDriver driver) {
        WebElement element = visibilityOfElementLocated(locator).apply(driver);
        try {
          if (element != null && element.isEnabled()) {
            return element;
          }
          return null;
        } catch (StaleElementReferenceException e) {
          return null;
        }
      }

      @Override
      public String toString() {
        return "element to be clickable: " + locator;
      }
    };
  }
325362
@Override
	public WebElement findElement(final By by) {
		return new StaleExceptionResolver<WebElement>() {

			@Override
			public WebElementAdapter execute(WebElement element) {
				return new WebElementAdapter(element.findElement(by),thisObject,by);
			}
		}.waitForElement();
	}
341798
public String getFirstParam(String paramName) {
        Collection<String> values = this.params.get(paramName);
        if(values == null || values.isEmpty()) {
            return null;
        } else {
            return values.iterator().next();
        }
    }
6452
function _waitForElement(browser, selector, asserter, timeout, pollFreq) {
  /* eslint no-use-before-define:0 */
  timeout = timeout || 2000;
  pollFreq = pollFreq || 50;

  const endTime = Date.now() + timeout;

  function attempt() {
    const element = browser.elementByCssSelectorOrNull(selector);
    return element
      .then(asserter.assert)
      .catch(retry)
      .then(_.constant(element));
  }

  function retry(error) {
    if (!error.retriable) {
      throw error;
    }
    if (Date.now() >= endTime) {
      error.message = `Timeout (${timeout}ms): ${error.message}`;
      throw error;
    }
    return new Promise(resolve => setTimeout(resolve, pollFreq)).then(attempt);
  }

  return attempt();
}
644225
public static ExpectedCondition<Boolean> clickCanBeDoneWithoutAlertOnElementLocated(final By locator) {
        return new ExpectedCondition<Boolean>() {
            /**
             * {@inheritDoc}
             */
            @Override
            public Boolean apply(@Nullable WebDriver driver) {
                try {
                    driver.findElement(locator).click();
                    return true;
                } catch (UnhandledAlertException e) {
                    driver.switchTo().alert().dismiss();
                } catch (ElementNotVisibleException e) {
                }
                return false;
            }
        };
    }
782009
public static ExpectedCondition<Boolean> textToBe(final By locator, final String value) {
    return new ExpectedCondition<Boolean>() {
      private String currentValue = null;

      @Override
      public Boolean apply(WebDriver driver) {
        try {
          currentValue = driver.findElement(locator).getText();
          return currentValue.equals(value);
        } catch (Exception e) {
          return false;
        }
      }

      @Override
      public String toString() {
        return String.format("element found by %s to have text \"%s\". Current text: \"%s\"",
                             locator, value, currentValue);
      }
    };
  }
1067146
private Parameter getParameterByOrdinal(Integer position)
    {
        for (Parameter p : parameters)
        {
            if (position.equals(p.getPosition()))
            {
                return p;
            }
        }

        return null;
    }