Ghostdriver 1.2.1 + PhantomJS 2.0 + latest Selenium Can't find variable error in Java Ghostdriver 1.2.1 + PhantomJS 2.0 + latest Selenium Can't find variable error in Java selenium selenium

Ghostdriver 1.2.1 + PhantomJS 2.0 + latest Selenium Can't find variable error in Java


Injecting JavaScript to the web page or any other element is poor practice. You can find the Element using Selenium code and click on it without the use of any injection.

  1. Wait for the page to be loaded

  2. Find the button by CSS or Xpath expression

  3. Wait for the element to by clickable

  4. click on it using Selenium code only

    WebDriverWait wait = new WebDriverWait(driver, timeToWait);

    this.by = by;

    try {

    webElement lastFoundElement =wait.until(ExpectedConditions.visibilityOfElementLocated(by));

    wait.until(ExpectedConditions.elementToBeClickable(lastFoundElement ));

    new Actions(browser).moveToElement(element, offsetX, offsetY).click().build().perform();

    }catch (Exception ex){
    }