nl.hsac.fitnesse.fixture.util.selenium.by.JavascriptBy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hsac-fitnesse-fixtures Show documentation
Show all versions of hsac-fitnesse-fixtures Show documentation
Fixtures to assist in testing via FitNesse
package nl.hsac.fitnesse.fixture.util.selenium.by;
import nl.hsac.fitnesse.fixture.util.selenium.JavascriptHelper;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import java.util.Collections;
import java.util.List;
/**
* Selenium By that finds elements by executing a Javascript function.
*/
public class JavascriptBy extends By {
private final String script;
private final Object[] scriptParameters;
/**
* Creates new.
* @param aScript script to find with.
* @param parameters arguments to the script.
*/
public JavascriptBy(String aScript, Object... parameters) {
script = aScript;
scriptParameters = parameters;
}
@Override
public List findElements(SearchContext searchContext) {
List result;
JavascriptExecutor executor = JavascriptHelper.getJavascriptExecutor(searchContext);
Object results = JavascriptHelper.executeScript(executor, script, scriptParameters);
if (results instanceof List) {
result = (List) results;
} else {
if (results == null) {
result = Collections.emptyList();
} else {
throw new RuntimeException("Script returned something else than a list: " + results);
}
}
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy