2

In my Selenium automation framework, I use JavaScriptLibrary for clicking some elements.

import com.thoughtworks.selenium.webdriven.JavascriptLibrary;

public class Utils{

 public static void click(WebDriver driver, WebElement element){
        JavascriptLibrary jsLib=new JavascriptLibrary();
        jsLib.callEmbeddedSelenium(driver, "triggerMouseEventAt", element, "click","0,0");
 }
}

The code was working fine when I was using Selenium v2.53. I recently upgraded Selenium client to v3.0. Since then eclipse showing the error,

The import com.thoughtworks cannot be resolved

and

JavascriptLibrary cannot be resolved to a type

Is javascript library not supported by v3.0?. Has it moved to another package ? or am missing some jar files?. Any workaround for this issue?

3 Answers 3

1

I think the com.thoughtworks.selenium.webdriven package is part of the initial Selenium RC version. This has been removed from the Selenium 3.0 version.

I can't find good reference, but the road to selenium 3.0 blog post has a comment with:

For now you can simulate the effect by disallowing classes in the com.thoughtworks.selenium package.

This leads me to think that you none of the com.thoughtworks.selenium packages will be available after the release.

I think you should either downgrade or use the JavascriptExecutor instead.

1

This library emulates Selenium v1 by injecting a script directly into the page. This version has been deprecated for a long time now and you shouldn't have to use it. Selenium v3 is as much capable and does a better job at simulating a real user.

Take this Selenium v3 code which clicks an element at a location :

new Actions(driver)
  .moveToElement(element, 1, 1)
  .click()
  .perform();

It will :

  • Scroll the element into the view if it's not already.
  • Ensure that the element is displayed and interractable.
  • Emit the mouseover, mousemove, mousedown, mouseup, click events

On the other hand triggerMouseEventAt will only emit the click event, even if the element is not rendered.

If the idea is to use it as a workaround for something you didn't managed to do with Selenium 2/3, well you'll probably end-up with a test that doesn't really simulate a real user.

So using this library kind of defeat the purpose of testing.

But if you are still willing to use it, one way would be to inject the function with executeScript:

public static void click(WebDriver driver, WebElement element){
    String script = "browserbot.triggerMouseEventAt(arguments[0], 'click', '0,0')";
    ((JavascriptExecutor)driver).executeScript(JS_INJECTABLE + script, element);
}

// The code for JS_INJECTABLE :
// https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/com/thoughtworks/selenium/webdriven/injectableSelenium.js
0

I solved it adding the selenium-leg-rc library to my project with Maven:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-leg-rc</artifactId>
        <version>3.12.0</version>
    </dependency>

Hope it helps, best regards! Hernán

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.