下面列出了org.openqa.selenium.remote.RemoteWebDriver#executeScript ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean loadPlotInDGMap(SimplePlacemarkObject placemarkObject, RemoteWebDriver driver)
throws InterruptedException {
boolean success = true;
if (driver != null && waitFor("mainContent", driver) && driver instanceof JavascriptExecutor) {
try {
String dgmapJs = getDGMapJavascript(placemarkObject);
driver.executeScript(dgmapJs);
Thread.sleep( 1000 );
// Unlock the view if it is locked
if( isCssElementPresent(".lock.on", driver) ) {
driver.findElementByCssSelector(".lock.on").click(); // UNLOCK
}
} catch (final Exception e) {
processSeleniumError(e);
success = false;
}
}
return success;
}
private static boolean clickIfPresent( RemoteWebDriver driver, String xpath )
{
boolean rtn = false;
HashMap<String, Object> params = new HashMap();
params.put("value", xpath);
params.put("framework", "perfectoMobile");
String result = (String) driver.executeScript("mobile:application.element:find", params);
if (( result != null ) && ( !( "false".equalsIgnoreCase( result ) )))
{
//
// This shouldn't be necessary, but I'm seeing the 'find' call finding
// elements that are scrolled off of the screen/page.
//
try
{
driver.executeScript("mobile:application.element:click", params);
rtn = true;
}
catch( Throwable e )
{}
}
return rtn;
}
public static void uninstallApp(RemoteWebDriver driver, String bundleId) {
driver.executeScript("mobile: removeApp", ImmutableMap.of("bundleId", bundleId));
}
public static void launchApp(RemoteWebDriver driver, String bundleId) {
driver.executeScript("mobile: launchApp", ImmutableMap.of("bundleId", bundleId));
}
public static boolean terminateApp(RemoteWebDriver driver, String bundleId) {
return (Boolean) driver.executeScript("mobile: terminateApp", ImmutableMap.of("bundleId", bundleId));
}
public static void pressHome(RemoteWebDriver driver) {
driver.executeScript("mobile:pressButton", ImmutableMap.of("name", "home"));
}
public static <T extends AdfComponent> T forElement(WebElement element) {
RemoteWebElement rwe = (RemoteWebElement) element;
RemoteWebDriver rwd = (RemoteWebDriver) rwe.getWrappedDriver();
String clientid = (String) rwd.executeScript(JS_FIND_ANCESTOR_COMPONENT, element);
return forClientId(rwd, clientid);
}