Java 类org.openqa.selenium.internal.Locatable 实例源码

项目:bobcat    文件:GuiceAwareFieldDecorator.java   
/**
 * This method decorates the field with the generated value. It should not be used directly.
 * Selenium's
 * PageFactory calls this method. If the field has Inject annotation, Selenium will ignore it.
 * Otherwise
 * Selenium will try to generate the value for this field.
 *
 * @param loader ClassLoader
 * @param field  Field to be initialized
 * @return decorated field Object
 */
@Override
public Object decorate(ClassLoader loader, Field field) {
  if (field.isAnnotationPresent(Inject.class)) {
    return null;
  } else {
    Object decoratedField = super.decorate(loader, field);
    if (decoratedField instanceof WebElement) {
      WebElement element = (WebElement) decoratedField;
      Locatable locatable = (Locatable) decoratedField;
      List<ConditionContext> fieldConditionContext =
          LoadableComponentsUtil.getConditionsFormField(field);
      BobcatWebElementContext context =
          new BobcatWebElementContext(element, locatable, fieldConditionContext);
      return bobcatWebElementFactory.create(context);
    }
    return decoratedField;
  }
}
项目:bobcat    文件:DroppableWebElement.java   
/**
 * @return Point in the middle of the drop area.
 */
@Override
public Point getCurrentLocation() {
  Point inViewPort = null;
  switcher.switchTo(getFramePath());
  try {
    Dimension size = dropArea.getSize();
    inViewPort = ((Locatable) dropArea).getCoordinates().inViewPort()
        .moveBy(size.getWidth() / 2, size.getHeight() / 2);
  } finally {
    switcher.switchBack();
  }
  return inViewPort;
}
项目:grid-refactor-remote-server    文件:MouseMoveToLocation.java   
@Override
public Void call() throws Exception {
  Mouse mouse = ((HasInputDevices) getDriver()).getMouse();

  Coordinates elementLocation = null;
  if (elementProvided) {
    WebElement element = getKnownElements().get(elementId);
    elementLocation = ((Locatable) element).getCoordinates();
  }

  if (offsetsProvided) {
    mouse.mouseMove(elementLocation, xOffset, yOffset);
  } else {
    mouse.mouseMove(elementLocation);
  }
  return null;
}
项目:windowlicker    文件:AsyncElementDriver.java   
public Tracker center() {
    return new Tracker() {
        private Point center;

        public Point target(Point currentLocation) {
            if (center == null) {
             prober.check(new ElementProbe(AsyncElementDriver.this) {
                 @Override
                 protected void probe(WebElement e) {
                     Point p = ((Locatable)e).getLocationOnScreenOnceScrolledIntoView();
                     Dimension d = ((RenderedWebElement)e).getSize();

                     center = new Point(p.x + d.width/2, p.y + d.height/2);
                 }
             });
            }
            return center;
        }
    };
}
项目:carina    文件:ExtendedWebElement.java   
/**
 * Scroll to element (applied only for desktop).
 */
@Deprecated
public void scrollTo() {
    if (Configuration.getDriverType().equals(SpecialKeywords.MOBILE)) {
        LOGGER.debug("scrollTo javascript is unsupported for mobile devices!");
        return;
    }
    try {
        Locatable locatableElement = (Locatable) findElement(EXPLICIT_TIMEOUT);
        //[VD] onScreen should be updated onto onPage as only 2nd one returns real coordinates without scrolling... read below material for details
        //https://groups.google.com/d/msg/selenium-developers/nJR5VnL-3Qs/uqUkXFw4FSwJ

        //[CB] onPage -> inViewPort
        //https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/remote/RemoteWebElement.java?r=abc64b1df10d5f5d72d11fba37fabf5e85644081
        int y = locatableElement.getCoordinates().inViewPort().getY();
        int offset = R.CONFIG.getInt("scroll_to_element_y_offset");
        ((JavascriptExecutor) getDriver()).executeScript("window.scrollBy(0," + (y - offset) + ");");
    } catch (Exception e) {
        // TODO: calm error logging as it is too noisy
        //LOGGER.debug("Scroll to element: " + getName() + " not performed!" + e.getMessage());
    }
}
项目:teasy    文件:FrameAwareWebElementTransformer.java   
@Override
public WebElement apply(final WebElement element) {
    return (WebElement) newProxyInstance(
            getClass().getClassLoader(),
            new Class[]{WebElement.class, WrapsElement.class, Locatable.class, HasIdentity.class},
            invocationHandlerFor(element)
    );
}
项目:bobcat    文件:BobcatWebElementContext.java   
/**
 *
 * @param webElement web element
 * @param locatable locatable
 * @param contextList internal context
 */
public BobcatWebElementContext(WebElement webElement, Locatable locatable,
        List<ConditionContext> contextList) {
  this.webElement = webElement;
  this.locatable = locatable;
  this.contextList = contextList;
}
项目:bobcat    文件:DraggableWebElement.java   
private Point getCurrentLocation() {
  Point inViewPort = null;
  switcher.switchTo(getFramePath());
  try {
    Dimension size = webElement.getSize();
    inViewPort = ((Locatable) webElement).getCoordinates().inViewPort()
        .moveBy(size.getWidth() / 2, size.getHeight() / 2);
  } finally {
    switcher.switchBack();
  }
  return inViewPort;
}
项目:xframium-java    文件:MorelandWebElement.java   
@Override
public Coordinates getCoordinates()
{
    if ( webElement instanceof Locatable )
    {
        if ( cachedCoordinates == null )
            cachedCoordinates = ( (Locatable) webElement ).getCoordinates();

        return cachedCoordinates;
    }
    else
        return null;
}
项目:jsflight    文件:LocatedElement.java   
@Override
public Coordinates getCoordinates()
{
    try
    {
        return ((Locatable)delegate).getCoordinates();
    }
    catch (StaleElementReferenceException e)
    {
        reLocateElement();
        return getCoordinates();
    }
}
项目:seleniumtestsframework    文件:HtmlElement.java   
/**
 * Forces a mouseOver event on the WebElement.
 */
public void mouseOver() {
    TestLogging.log("MouseOver " + this.toString());
    findElement();

    // build and perform the mouseOver with Advanced User Interactions API
    // Actions builder = new Actions(driver);
    // builder.moveToElement(element).build().perform();
    final Locatable hoverItem = (Locatable) element;
    final Mouse mouse = ((HasInputDevices) driver).getMouse();
    mouse.mouseMove(hoverItem.getCoordinates());
}
项目:grid-refactor-remote-server    文件:SingleTapOnElement.java   
@Override
public Void call() throws Exception {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();

  touchScreen.singleTap(elementLocation);

  return null;
}
项目:grid-refactor-remote-server    文件:Flick.java   
@Override
public Void call() throws Exception {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();

  if (elementId != null) {
    WebElement element = getKnownElements().get(elementId);
    Coordinates elementLocation = ((Locatable) element).getCoordinates();
    touchScreen.flick(elementLocation, xOffset, yOffset, speed);
  } else {
    touchScreen.flick(xSpeed, ySpeed);
  }

  return null;
}
项目:grid-refactor-remote-server    文件:DoubleTapOnElement.java   
@Override
public Void call() throws Exception {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();

  touchScreen.doubleTap(elementLocation);

  return null;
}
项目:grid-refactor-remote-server    文件:LongPressOnElement.java   
@Override
public Void call() throws Exception {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();
  touchScreen.longPress(elementLocation);

  return null;
}
项目:grid-refactor-remote-server    文件:Scroll.java   
@Override
public Void call() throws Exception {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();

  if (elementId != null) {
    WebElement element = getKnownElements().get(elementId);
    Coordinates elementLocation = ((Locatable) element).getCoordinates();
    touchScreen.scroll(elementLocation, xOffset, yOffset);
  } else {
    touchScreen.scroll(xOffset, yOffset);
  }
  return null;
}
项目:grid-refactor-remote-server    文件:KnownElements.java   
private WebElement proxyElement(final WebElement element, final String id) {
  InvocationHandler handler = new InvocationHandler() {
    public Object invoke(Object object, Method method, Object[] objects) throws Throwable {
      if ("getId".equals(method.getName())) {
        return id;
      } else if ("getWrappedElement".equals(method.getName())) {
        return element;
      } else {
        try {
        return method.invoke(element, objects);
        } catch (InvocationTargetException e){
          throw e.getTargetException();
        }
      }
    }
  };

  Class<?>[] proxyThese;
  if (element instanceof Locatable) {
    proxyThese = new Class[] {WebElement.class, ProxiedElement.class, Locatable.class};
  } else {
    proxyThese = new Class[] {WebElement.class, ProxiedElement.class};
  }

  return (WebElement) Proxy.newProxyInstance(element.getClass().getClassLoader(),
      proxyThese,
      handler);
}
项目:UIFramework    文件:LineChart.java   
public void hoverOverGraphPointAtXAxisPosition(int pointNumber) {
    int xRect = ((Locatable) rectElement).getCoordinates().inViewPort().getX();
    int yRect = ((Locatable) rectElement).getCoordinates().inViewPort().getY();

    int xHoverPoint = xRect + getPlotOffset().getX() + getPlotPoint(pointNumber).getX();
    int yHoverPoint = yRect + getPlotOffset().getY() + getPlotPoint(pointNumber).getY();

    //For browsers not supporting native events
    javascript.callEmbeddedSelenium(driver, "triggerEvent", elementToHoverOver, "mouseover");
    //For browsers supporting native events
    xHoverPoint = xHoverPoint - ((Locatable) elementToHoverOver).getCoordinates().inViewPort().getX();
    yHoverPoint = yHoverPoint - ((Locatable) elementToHoverOver).getCoordinates().inViewPort().getY();
    performAction.moveToElement(plotLine).moveToElement(elementToHoverOver, xHoverPoint, yHoverPoint).perform();
}
项目:web-test-framework    文件:Element.java   
/**
 *
 * @return
 */
@Override
public Coordinates getCoordinates() {
  return new RetryUntilTimeout<Coordinates>() {
    @Override
    Coordinates commandsToRun() {
      return ((Locatable) element).getCoordinates();
    }
  }.run();
}
项目:cinnamon    文件:PositionUnchangedConditionTest.java   
@Test
public void shouldMatchConditionWhenElementPositionUnchanged() {
    when(((Locatable) mockElement).getCoordinates()).thenReturn(mockCoordinates);
    when(((Locatable) mockElement).getCoordinates().inViewPort()).thenReturn(new Point(100, 100), new Point(100, 100));
    PositionUnchangedCondition condition = new PositionUnchangedCondition(100);
    assertThat(condition.apply(mockElement), equalTo(true));
}
项目:cinnamon    文件:PositionUnchangedConditionTest.java   
@Test
public void shouldNotMatchConditionWhenElementPositionHasChanged() {
    when(((Locatable) mockElement).getCoordinates()).thenReturn(mockCoordinates);
    when(((Locatable) mockElement).getCoordinates().inViewPort()).thenReturn(new Point(100, 100), new Point(150, 100));
    PositionUnchangedCondition condition = new PositionUnchangedCondition(100);
    assertThat(condition.apply(mockElement), equalTo(false));
}
项目:JTAF-ExtWebDriver    文件:Element.java   
/***
 * Determine if the element is within the bounds of the window
 * 
 * @return true or false
 * @throws WidgetException
 */
public boolean isWithinBoundsOfWindow() throws WidgetException {

    JavascriptExecutor js = ((JavascriptExecutor) getGUIDriver().getWrappedDriver());

    // execute javascript to get scroll values
    Object top = js.executeScript("return document.body.scrollTop;");
    Object left = js.executeScript("return document.body.scrollLeft;");

    int scrollTop;
    int scrollLeft;
    try {
        scrollTop = Integer.parseInt(top+"");
        scrollLeft = Integer.parseInt(left+"");
    }
    catch(NumberFormatException e) {
        throw new WidgetException("There was an error parsing the scroll values from the page", getByLocator());
    }

    // calculate bounds
    Dimension dim = getGUIDriver().getWrappedDriver().manage().window().getSize();
    int windowWidth = dim.getWidth();
    int windowHeight = dim.getHeight();
    int x = ((Locatable)getWebElement()).getCoordinates().onPage().getX();
    int y = ((Locatable)getWebElement()).getCoordinates().onPage().getY();
    int relX = x - scrollLeft;
    int relY = y - scrollTop;
    return relX + findElement().getSize().getWidth() <= windowWidth && 
            relY + findElement().getSize().getHeight() <= windowHeight && 
                relX >= 0 && relY >= 0;
}
项目:JTAF-ExtWebDriver    文件:Element.java   
/***
 * Scroll to this element
 */
@Override
public void scrollTo() throws WidgetException {
    WebElement we = findElement();  
    Locatable l = ((Locatable)we);
    l.getCoordinates().inViewPort();
}
项目:carina    文件:ExtendedFieldDecorator.java   
protected ExtendedWebElement proxyForLocator(ClassLoader loader, Field field, ElementLocator locator)
{
    InvocationHandler handler = new LocatingElementHandler(locator);
    WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[]
    { WebElement.class, WrapsElement.class, Locatable.class }, handler);
    return new ExtendedWebElement(proxy, field.getName(), field.isAnnotationPresent(FindBy.class) ? new LocalizedAnnotations(field).buildBy() : null, webDriver);
}
项目:teasy    文件:BaseTeasyElement.java   
@Override
public Coordinates getCoordinates() {
    return ((Locatable) getWrappedWebElement()).getCoordinates();
}
项目:bobcat    文件:CurrentWebElementProvider.java   
private WebElement getWebElementFromFactory(ElementLocatorFactory factory) {
  InvocationHandler handler = new LocatingElementHandler(
      ((ParentElementLocatorProvider) factory).getCurrentScope());
  return (WebElement) Proxy.newProxyInstance(WebElement.class.getClassLoader(),
      new Class[] {WebElement.class, WrapsElement.class, Locatable.class}, handler);
}
项目:mario    文件:ElementLocationProbe.java   
protected void probe(WebElement found) {
    if (found instanceof Locatable) {
        coordinates = ((Locatable) found).getCoordinates();
    }
}
项目:OptimusPrime    文件:WebElementWrapper.java   
public void ScrollIntoView() {
    Coordinates thisElementCor = ((Locatable) element).getCoordinates();
    thisElementCor.inViewPort();
}
项目:che    文件:PlatformBasedActions.java   
@Override
public Actions sendKeys(WebElement element, CharSequence... keysToSend) {
  action.addAction(
      new SendKeysAction(keyboard, mouse, (Locatable) element, modifyCharSequence(keysToSend)));
  return this;
}
项目:JDI    文件:JList.java   
public Coordinates getCoordinates() {
    return ((Locatable)getWebElement()).getCoordinates();
}
项目:JDI    文件:J.java   
public Coordinates getCoordinates() {
    return ((Locatable)getWebElement()).getCoordinates();
}
项目:grid-refactor-remote-server    文件:GetElementLocationInView.java   
@Override
public Point call() throws Exception {
  Locatable element = (Locatable) getElement();
  return element.getCoordinates().inViewPort();
}
项目:cinnamon    文件:WebElementWrapper.java   
@Override
public Coordinates getCoordinates() {
    return ((Locatable) getWrappedElement()).getCoordinates();
}
项目:cinnamon    文件:SyntheticEvent.java   
/**
 * Scrolls the browser to the element x and y position perform the current page.
 * @param element the element to scroll to
 */
public void scrollToElement(WebElement element) {
    Point elementLocationOnPage = ((Locatable) element).getCoordinates().onPage();
    js.executeScript("window.scrollBy(" + elementLocationOnPage.x + "," + elementLocationOnPage.y + ");");
}
项目:cinnamon    文件:HoverAction.java   
@Override
public void perform(final WebElement target) {
    final Locatable hoverItem = (Locatable) target;
    final Mouse mouse = ((HasInputDevices) webDriver).getMouse();
    mouse.mouseMove(hoverItem.getCoordinates());
}
项目:seleniumcapsules    文件:Element.java   
@Override
public Coordinates getCoordinates() {
    return ((Locatable) element).getCoordinates();
}
项目:JTAF-ExtWebDriver    文件:ScreenshotUtils.java   
/***
 * You can use this method to take your control pictures. Note that the file should be a png.
 * 
 * @param element
 * @param toSaveAs
 * @throws IOException 
 * @throws WidgetException 
 */
public static void takeScreenshotOfElement(IElement element, File toSaveAs) throws IOException, WidgetException {

    for(int i = 0; i < 10; i++) { //Loop up to 10x to ensure a clean screenshot was taken
        log.info("Taking screen shot of locator " + element.getByLocator() + " ... attempt #" + (i+1));

        //Scroll to element
        element.scrollTo();

        //Take picture of the page
        WebDriver wd = SessionManager.getInstance().getCurrentSession().getWrappedDriver();
        File screenshot;
        boolean isRemote = false;
        if(!(wd instanceof RemoteWebDriver)) {
            screenshot = ((TakesScreenshot) wd).getScreenshotAs(OutputType.FILE);       
        }
        else {
            Augmenter augmenter = new Augmenter();
            screenshot = ((TakesScreenshot) augmenter.augment(wd)).getScreenshotAs(OutputType.FILE);
            isRemote = true;
        }
        BufferedImage fullImage = ImageIO.read(screenshot);
        WebElement ele = element.getWebElement();

        //Parse out the picture of the element
        Point point = ele.getLocation();
        int eleWidth = ele.getSize().getWidth();
        int eleHeight = ele.getSize().getHeight();
        int x; 
        int y;
        if(isRemote) {
            x = ((Locatable)ele).getCoordinates().inViewPort().getX();
            y = ((Locatable)ele).getCoordinates().inViewPort().getY();
        }
        else {
            x = point.getX();
            y = point.getY();
        }
        log.debug("Screenshot coordinates x: "+x+", y: "+y);
        BufferedImage eleScreenshot = fullImage.getSubimage(x, y, eleWidth, eleHeight); 
        ImageIO.write(eleScreenshot, "png", screenshot);

        //Ensure clean snapshot (sometimes WebDriver takes bad pictures and they turn out all black)
        if(!isBlack(ImageIO.read(screenshot))) {
            FileUtils.copyFile(screenshot, toSaveAs);
            break;
        }
    }
}
项目:harness    文件:Common.java   
public void mouseOver(WebElement element) {

        Locatable hoverItem = (Locatable) element;
        Mouse mouse = ((HasInputDevices) driver).getMouse();
        mouse.mouseMove(hoverItem.getCoordinates());

    }
项目:bobcat    文件:BobcatWebElementContext.java   
/**
 *
 * @return locatable
 */
public Locatable getLocatable() {
  return locatable;
}