org.openqa.selenium.remote.RemoteWebDriver.executeScript()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中org.openqa.selenium.remote.RemoteWebDriver.executeScript方法的一些代码示例,展示了RemoteWebDriver.executeScript的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RemoteWebDriver.executeScript方法的具体详情如下:
包路径:org.openqa.selenium.remote.RemoteWebDriver
类名称:RemoteWebDriver
方法名:executeScript

RemoteWebDriver.executeScript介绍

暂无

代码示例

代码示例来源:origin: la-team/light-admin

@Override
public void scrollTo(int pixels) {
  webDriver.executeScript("window.scrollBy(0, " + pixels +")");
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-test-ui

@Override
public Object executeScript(String script, Object... args)
{
  return this.wrappedDriver.executeScript(script, args);
}

代码示例来源:origin: org.eclipse.che.selenium/che-selenium-core

@Override
public Object executeScript(String script, Object... args) {
 return driver.executeScript(script, args);
}

代码示例来源:origin: org.mycore/selenium-utils

public Object executeScript(String script, Object... args) {
  return delegate.executeScript(script, args);
}

代码示例来源:origin: stackoverflow.com

WebDriver driver=new FirefoxDriver();
driver.get("http://localhost/login.do");
driver.manage().window().maximize();
RemoteWebDriver r=(RemoteWebDriver) driver;
String s1="document.getElementById('username').value='admin'";
r.executeScript(s1);

代码示例来源:origin: com.saucelabs/sebuilder-interpreter

@Override
public String get(TestRun ctx) {
  Object result = ctx.driver().executeScript(ctx.string("script"));
  return result == null ? null : result.toString();
}

代码示例来源:origin: stackoverflow.com

WebDriver driver=new FirefoxDriver();
driver.get("http://localhost/login.do");
driver.manage().window().maximize();
RemoteWebDriver r=(RemoteWebDriver) driver;
String s1="document.getElementById('username').value='admin'";
r.executeScript(s1);

代码示例来源:origin: com.applitools/eyes-selenium-java3

public String getUserAgent() {
  String userAgent;
  try {
    userAgent = (String) this.driver.executeScript("return navigator.userAgent");
    logger.verbose("user agent: " + userAgent);
  } catch (Exception e) {
    logger.verbose("Failed to obtain user-agent string");
    userAgent = null;
  }
  return userAgent;
}

代码示例来源:origin: com.watchrabbit/scanner-attacker

@Override
public Vulnerability verify(RemoteWebDriver driver, long loadMilisec) {
  WebDriverWait wait = new WebDriverWait(driver, 1);
  try {
    wait.until((WebDriver predicatedDriver) -> false);
  } catch (TimeoutException ex) {
    LOGGER.info("Timed out on {}", driver.getCurrentUrl());
  }
  String result = (String) driver.executeScript("return window.w$");
  LOGGER.debug("XSS Attack result is {}", result);
  if (StringUtils.isNotBlank(result)) {
    return Vulnerability.EXISTS;
  } else {
    return Vulnerability.NONE;
  }
}

代码示例来源:origin: com.github.becauseQA/becauseQA-utils

@Override
public String getPageSource() {
  if (getW3CStandardComplianceLevel() == 0) {
    return (String) execute(DriverCommand.GET_PAGE_SOURCE).getValue();
  }
  String script = "var source = document.documentElement.outerHTML; \n"
      + "if (!source) { source = new XMLSerializer().serializeToString(document); }\n" + "return source;";
  return (String) executeScript(script);
}

代码示例来源:origin: mirkosertic/Bytecoder

final Object data = theDriver.executeScript("return compile();");
final ArrayList<Long> theResult = (ArrayList<Long>) data;
final int[] theBinaryDara = new int[theResult.size()];

代码示例来源:origin: paypal/SeLion

static void printDebugInfoForUser(RemoteWebDriver driver) {
  Properties props = new Properties();
  props.put("Selenium Version", new BuildInfo().getReleaseLabel());
  props.put("Client OS", System.getProperty("os.name") + " " + System.getProperty("os.version"));
  String currentBrowser = "UNKNOWN browser";
  if (WebDriverPlatform.WEB.equals(Grid.getTestSession().getPlatform())) {
    currentBrowser = Grid.getWebTestSession().getBrowser();
  }
  if (BrowserFlavors.isHeadLessBrowser(currentBrowser)) {
    props.put("Browser", StringUtils.capitalize(currentBrowser.substring(1)));
  } else if (WebDriverPlatform.IOS.equals(Grid.getTestSession().getPlatform())
      || (WebDriverPlatform.ANDROID.equals(Grid.getTestSession().getPlatform()))) {
    props.put("Device", Grid.getMobileTestSession().getDevice().toString());
  } else {
    String userAgent = (String) driver.executeScript("return navigator.userAgent", "");
    String browserFlavor = "UNKNOWN browser";
    if (StringUtils.isNotBlank(userAgent)) {
      browserFlavor = extractBrowserInfo(userAgent);
    }
    props.put("Browser", browserFlavor);
  }
  logger.log(Level.INFO, "Running on: " + props.toString());
}

代码示例来源:origin: com.github.becauseQA/becauseQA-utils

public WebDriver window(String windowHandleOrName) {
 try {
  execute(DriverCommand.SWITCH_TO_WINDOW, ImmutableMap.of("handle", windowHandleOrName));
  return RemoteWebDriver.this;
 } catch (NoSuchWindowException nsw) {
  // simulate search by name
  String original = getWindowHandle();
  for (String handle : getWindowHandles()) {
   switchTo().window(handle);
   if (windowHandleOrName.equals(executeScript("return window.name"))) {
    return RemoteWebDriver.this; // found by name
   }
  }
  switchTo().window(original);
  throw nsw;
 }
}

代码示例来源:origin: com.applitools/eyes-selenium-java3

public Object executeScript(String script, Object... args) {
  // Appium commands are sometimes sent as Javascript
  if (AppiumJsCommandExtractor.isAppiumJsCommand(script)) {
    Trigger trigger =
        AppiumJsCommandExtractor.extractTrigger(elementsIds,
            driver.manage().window().getSize(), script, args);
    if (trigger != null) {
      // TODO - Daniel, additional types of triggers
      if (trigger instanceof MouseTrigger) {
        MouseTrigger mt = (MouseTrigger) trigger;
        eyes.addMouseTrigger(mt.getMouseAction(), mt.getControl(), mt.getLocation());
      }
    }
  }
  @SuppressWarnings("UnnecessaryLocalVariable")
  Object result = driver.executeScript(script, args);
  return result;
}

相关文章