org.openqa.selenium.Point类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(124)

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

Point介绍

[英]A copy of java.awt.Point, to remove dependency on awt.
[中]java的副本。awt。点,以消除对awt的依赖。

代码示例

代码示例来源:origin: appium/java-client

/**
 * Method returns central coordinates of an element.
 * @return The instance of the {@link org.openqa.selenium.Point}
 */
public Point getCenter() {
  Point upperLeft = this.getLocation();
  Dimension dimensions = this.getSize();
  return new Point(upperLeft.getX() + dimensions.getWidth() / 2,
    upperLeft.getY() + dimensions.getHeight() / 2);
}

代码示例来源:origin: selenide/selenide

WebDriver adjustBrowserPosition(Config config, WebDriver driver) {
 if (config.browserPosition() != null) {
  log.info("Set browser position to " + config.browserPosition());
  String[] coordinates = config.browserPosition().split("x");
  int x = Integer.parseInt(coordinates[0]);
  int y = Integer.parseInt(coordinates[1]);
  Point target = new Point(x, y);
  Point current = driver.manage().window().getPosition();
  if (!current.equals(target)) {
   driver.manage().window().setPosition(target);
  }
 }
 return driver;
}

代码示例来源:origin: galenframework/galen

@Override
  public Rect findArea(WebPageElement webPageElement) {
    WebElement webElement = webPageElement.getWebElement();
    Point location = webElement.getLocation();
    Dimension size = webElement.getSize();
    return new Rect(location.getX(), location.getY(), size.getWidth(), size.getHeight());
  }
}),

代码示例来源:origin: selenide/selenide

@Override
 public WebElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) {
  Point location = locator.getWebElement().getLocation();
  locator.driver().executeJavaScript("window.scrollTo(" + location.getX() + ", " + location.getY() + ')');
  return proxy;
 }
}

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

java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
org.openqa.selenium.Point position = new Point(0, 0);
driver.manage().window().setPosition(position);
org.openqa.selenium.Dimension maximizedScreenSize =
      new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
driver.manage().window().setSize(maximizedScreenSize);

代码示例来源:origin: appium/java-client

@Override
public void beforeWindowIsMoved(WebDriver driver, WebDriver.Window window, Point targetPoint) {
  messages.add("Attempt to change position of the window. The X is " + targetPoint.getX()
    + " the Y is " + targetPoint.getY());
}

代码示例来源:origin: com.atlassian.selenium/atlassian-webdriver-core

@Override
public int getTop()
{
  return getElement().getLocation().getY();
}

代码示例来源:origin: com.atlassian.selenium/atlassian-webdriver-core

@Override
public int getLeft()
{
  return getElement().getLocation().getX();
}

代码示例来源:origin: appium/java-client

/**
 * It defines x and y coordinates.
 * This is offset from the upper left corner of the screen.
 *
 * @param xOffset is x value.
 * @param yOffset is y value.
 * @return self-reference
 */
public T withCoordinates(int xOffset, int yOffset) {
  coordinates = new Point(xOffset, yOffset);
  //noinspection unchecked
  return (T) this;
}

代码示例来源:origin: com.atlassian.selenium/atlassian-webdriver-core

private void calculateCoordinates()
  {
    int relativeX = x - scrollTo.getX();
    int relativeY = y - scrollTo.getY();
    elementCoordinates = new Point(relativeX, relativeY);
  }
}

代码示例来源:origin: com.atlassian.selenium/atlassian-webdriver-core

private void calculateScroll()
{
  int deltaX = Math.max(0, document.getWidth() - viewport.getWidth());
  int scrollX = Math.min(x, deltaX);
  int deltaY = Math.max(0, document.getHeight() - viewport.getHeight());
  int scrollY = Math.min(y, deltaY);
  scrollTo = new Point(scrollX, scrollY);
}

代码示例来源:origin: io.selendroid/selendroid-client

public Point call() throws Exception {
 currentLocation = element.getLocation();
 if (currentLocation.equals(expectedLocation)) {
  return expectedLocation;
 }
 return null;
}

代码示例来源:origin: com.daveayan/gherkinsalad.core

public Point getLocation() {
  if(is_not_null(_webElement)) {
    Point value = _webElement.getLocation();
    info("Element '" + super.name() + "' - Location is '" + value + "'");
    return value;
  } else {
    info("Element '" + super.name() + "' - has a null _webelement, cannot do getLocation()");
  }
  return new Point(0, 0);
}

代码示例来源:origin: com.atlassian.jira/atlassian-jira-pageobjects

public Builder below(PageElement target)
{
  resetDirectTarget();
  setY(target.getLocation().getY() + target.getSize().getHeight() - source.getLocation().getY());
  return this;
}

代码示例来源:origin: com.atlassian.jira/atlassian-jira-pageobjects

public Builder toRightOf(PageElement target)
{
  resetDirectTarget();
  setX(target.getLocation().getX() + target.getSize().getWidth() - source.getLocation().getX());
  return this;
}

代码示例来源:origin: com.infotel.seleniumRobot/core

@ReplayOnError
public Point getCenter() {
  try {
    checkForMobile();
    return ((MobileElement)getUnderlyingElement(element)).getCenter();
  } catch (ScenarioException e) {
    Rectangle rectangle = element.getRect();
    return new Point(rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2);
  }    
}

代码示例来源:origin: org.seleniumhq.selenium/selenium-api

@Override
public boolean equals(Object o) {
 if (this == o) {
  return true;
 }
 if (o == null || getClass() != o.getClass()) {
  return false;
 }
 Rectangle rectangle = (Rectangle) o;
 if (! getPoint().equals(rectangle.getPoint())) {
  return false;
 }
 return getDimension().equals(rectangle.getDimension());
}

代码示例来源:origin: org.richfaces/richfaces-page-fragments

@Override
public boolean equals(Object obj) {
  if (obj == null) {
    return false;
  }
  if (getClass() != obj.getClass()) {
    return false;
  }
  final Locations other = (Locations) obj;
  if (!this.topLeft.equals(other.topLeft)) {
    return false;
  }
  if (!this.topRight.equals(other.topRight)) {
    return false;
  }
  if (!this.bottomLeft.equals(other.bottomLeft)) {
    return false;
  }
  if (!this.bottomRight.equals(other.bottomRight)) {
    return false;
  }
  return true;
}

代码示例来源:origin: selenide/selenide

private BufferedImage takeScreenshotAsImage(WebDriver webdriver, WebElement element) {
 if (!(webdriver instanceof TakesScreenshot)) {
  log.warning("Cannot take screenshot because browser does not support screenshots");
  return null;
 }
 byte[] screen = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.BYTES);
 Point elementLocation = element.getLocation();
 try {
  BufferedImage img = ImageIO.read(new ByteArrayInputStream(screen));
  int elementWidth = element.getSize().getWidth();
  int elementHeight = element.getSize().getHeight();
  if (elementWidth > img.getWidth()) {
   elementWidth = img.getWidth() - elementLocation.getX();
  }
  if (elementHeight > img.getHeight()) {
   elementHeight = img.getHeight() - elementLocation.getY();
  }
  return img.getSubimage(elementLocation.getX(), elementLocation.getY(), elementWidth, elementHeight);
 }
 catch (IOException e) {
  log.log(SEVERE, "Failed to take screenshot of " + element, e);
  return null;
 }
 catch (RasterFormatException e) {
  log.warning("Cannot take screenshot because element is not displayed on current screen position");
  return null;
 }
}

代码示例来源:origin: com.epam.jdi/jdi-uitest-web

public SelenideElement scrollTo() {
  Point location = getWebElement().getLocation();
  jsExecutor().executeScript("window.scrollTo(" + location.getX() + ", " + location.getY() + ')');
  return this;
}

相关文章