All Downloads are FREE. Search and download functionalities are using the official Maven repository.

au.com.agic.apptesting.utils.impl.JavaScriptRunnerImpl Maven / Gradle / Ivy

package au.com.agic.apptesting.utils.impl;

import au.com.agic.apptesting.utils.JavaScriptRunner;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;

import javax.validation.constraints.NotNull;

/**
 * An implementation of the JavaScript runner service
 */
public class JavaScriptRunnerImpl implements JavaScriptRunner {

	@Override
	public void interactHiddenElement(
		@NotNull final WebElement element,
		@NotNull final String event,
		@NotNull final JavascriptExecutor js) {
		/*
			PhantomJS doesn't support the click method, so "element.click()" won't work
			here. We need to dispatch the event instead.
		 */
		js.executeScript("var ev = document.createEvent('MouseEvent');"
			+ "    ev.initMouseEvent("
			+ "        '" + event + "',"
			+ "        true /* bubble */, true /* cancelable */,"
			+ "        window, null,"
			+ "        0, 0, 0, 0, /* coordinates */"
			+ "        false, false, false, false, /* modifier keys */"
			+ "        0 /*left*/, null"
			+ "    );"
			+ "    arguments[0].dispatchEvent(ev);", element);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy