コード例 #1
0
  private String getLogValue(WebLocator el, String value) {
    String info = el.getPathBuilder().getInfoMessage();
    if (info == null || "".equals(info)) {
      info = el.getPathBuilder().itemToString();
    }
    info = info.toLowerCase();

    return WebLocatorConfig.getLogParamsExclude().contains(info) ? "*****" : value;
  }
コード例 #2
0
 public String getAttributeId(WebLocator el) {
   String pathId = getAttribute(el, "id");
   if (el.hasId()) {
     final String id = el.getPathBuilder().getId();
     if (!id.equals(pathId)) {
       LOGGER.warn("id is not same as pathId:{} - {}", id, pathId);
     }
     return id;
   }
   return pathId;
 }
コード例 #3
0
 public Object fireEventWithJS(WebLocator el, String eventName) {
   String script =
       "if(document.createEvent){"
           + "var evObj = document.createEvent('MouseEvents');\n"
           + "evObj.initEvent('"
           + eventName
           + "', true, true);\n"
           + "return fireOnThis.dispatchEvent(evObj);\n"
           + "} else if(document.createEventObject) {"
           + "return fireOnThis.fireEvent('on"
           + eventName
           + "');"
           + "}";
   String id = getAttributeId(el);
   String cls;
   if (!"".equals(id)) {
     script = "var fireOnThis = document.getElementById('" + id + "');\n" + script;
   } else if (!"".equals(cls = getAttribute(el, "class"))) {
     script = "var fireOnThis = document.getElementsByClassName('" + cls + "')[0];\n" + script;
   } else {
     script =
         "var fireOnThis = document.evaluate(\""
             + el.getXPath()
             + "\", document, null, XPathResult.ANY_TYPE, null).iterateNext();\n"
             + "var evObj = document.createEvent('MouseEvents');\n"
             + "evObj.initEvent( '"
             + eventName
             + "', true, true );\n"
             + "return fireOnThis.dispatchEvent(evObj);";
   }
   return executeScript(script);
 }
コード例 #4
0
 @Override
 public WebElement findElement(WebLocator el) {
   final String path = getSelector(el);
   //        if (isSamePath(el, path)) {
   //            LOGGER.debug("currentElement already found one time: " + el);
   // return el.currentElement;
   //        }
   doWaitElement(el, 0);
   el.setCurrentElementPath(path);
   return el.currentElement;
 }
コード例 #5
0
 public boolean browse(WebLocator el) {
   try {
     el.focus();
     Actions builder = new Actions(driver);
     builder.moveToElement(el.currentElement).perform();
     builder.click().perform();
     return true;
   } catch (Exception e) {
     LOGGER.error(e.getMessage(), e);
     return false;
   }
 }
コード例 #6
0
 private WebElement doWaitElement(final WebLocator el, final long millis) {
   WebDriverWait wait = new WebDriverWait(driver, 0, 100);
   wait.withTimeout(
       millis,
       TimeUnit.MILLISECONDS); // hack enforce WebDriverWait to accept millis (default is seconds)
   try {
     if (el.getPathBuilder().isVisibility()) {
       el.currentElement =
           wait.until(ExpectedConditions.visibilityOfElementLocated(el.getSelector()));
     } else {
       el.currentElement =
           wait.until(
               new ExpectedCondition<WebElement>() {
                 public WebElement apply(WebDriver driver1) {
                   return driver.findElement(el.getSelector());
                 }
               });
     }
   } catch (TimeoutException e) {
     el.currentElement = null;
   }
   return el.currentElement;
 }
コード例 #7
0
 public boolean isSamePath(WebLocator el, String path) {
   return el.currentElement != null && (el.getCurrentElementPath().equals(path));
 }
コード例 #8
0
 public List<WebElement> findElements(WebLocator el) {
   return driver.findElements(el.getSelector());
 }
コード例 #9
0
 private void invalidateCache(WebLocator el) {
   el.currentElement = null;
   el.setCurrentElementPath("");
 }
コード例 #10
0
 private String getSelector(WebLocator el) {
   String css = el.getCssSelector();
   return StringUtils.isEmpty(css) ? el.getXPath() : css;
 }