org.openqa.selenium.Point.getX()方法的使用及代码示例

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

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

Point.getX介绍

暂无

代码示例

代码示例来源: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: 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: selenide/selenide

iframeWidth = img.getWidth() - iframeLocation.getX();
int elementHeight = element.getSize().getHeight();
if (elementWidth > iframeWidth) {
 elementWidth = iframeWidth - elementLocation.getX();
 img = img.getSubimage(iframeLocation.getX() + elementLocation.getX(), iframeLocation.getY() + elementLocation.getY(),
  elementWidth, elementHeight);

代码示例来源: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: 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: appium/java-client

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

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

@Override
public void afterWindowIsMoved(WebDriver driver, WebDriver.Window window, Point targetPoint) {
  messages.add("Externally defined listener: The position the window has been changed. "
    + "The X is " + targetPoint.getX()
    + " the Y is " + targetPoint.getY());
}

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

@Override
public void afterWindowIsMoved(WebDriver driver, WebDriver.Window window, Point targetPoint) {
  messages.add("The position the window has been changed. The X is " + targetPoint.getX()
    + " the Y is " + targetPoint.getY());
}

代码示例来源: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: appium/java-client

prefix + "Size of the window has been changed. The height is " + d.getHeight()
    + " the width is " + d.getWidth(),
prefix + "Attempt to change position of the window. The X is " + p.getX()
    + " the Y is " + p.getY(),
prefix + "The position the window has been changed. The X is " + p.getX()
    + " the Y is " + p.getY(),
prefix + "Attempt to maximize the window.",

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

@Override
  public String toString()
  {
    return format("By point in viewport %d,%d", coordinates.getX(), coordinates.getY());
  }
};

代码示例来源:origin: qaprosoft/carina

@Override
public ICapturable highlight(Point point) {
  try {
    Graphics2D g2d = screenshot.createGraphics();
    g2d.setColor(Color.red);
    g2d.draw(new Ellipse2D.Double(point.getX(), point.getY(), 100, 100));
  } catch (Exception e) {
    LOGGER.error("Unable to highligh screenshot: " + e.getMessage());
  }
  return this;
}

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

@Override
public List<WebElement> findElements(SearchContext context)
{
  final String findByPoint = format("return document.elementFromPoint(%d,%d);", coordinates.getX(),
      coordinates.getY());
  final WebElement element = execute(WebElement.class, findByPoint, webDriver);
  return element != null ? Collections.singletonList(element) : Collections.<WebElement>emptyList();
}

代码示例来源:origin: com.twosigma.webtau/webtau-browser

@Override
  public void addAnnotationData(Map<String, Object> data, WebElement webElement) {
    Point location = center(webElement);

    data.put("x", location.getX());
    data.put("y", location.getY());
    data.put("r", 20);
  }
}

代码示例来源: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

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

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

private void performShortClickAction(Point point) {
  try {
    new TouchActions(this).down(point.getX(), point.getY()).perform();
    Thread.sleep(SHORT_TAP_TIME_MILLIS);
    new TouchActions(this).up(point.getX(), point.getY()).perform();
  } catch (InterruptedException exe) {
    throw new WebDriverException("InterruptedException occurred during shortClick", exe);
  }
}

代码示例来源:origin: pazone/ashot

@Override
  public Coords ofElement(WebDriver driver, WebElement element) {
    Point point = element.getLocation();
    Dimension dimension = element.getSize();
    return new Coords(
        point.getX(),
        point.getY(),
        dimension.getWidth(),
        dimension.getHeight());
  }
}

代码示例来源:origin: qaprosoft/carina

/**
 * Tap with TouchAction by the center of element
 *
 * @param element ExtendedWebElement
 */
default public void tap(ExtendedWebElement element) {
  Point point = element.getLocation();
  Dimension size = helper.performIgnoreException(() -> element.getSize());
  
  tap(point.getX() + size.getWidth() / 2, point.getY() + size.getHeight() / 2);
}

代码示例来源:origin: qaprosoft/carina

/**
 * Tap with TouchAction by the center of element
 *
 * @param element ExtendedWebElement
 */
public static void tap(ExtendedWebElement element) {
  Point point = element.getLocation();
  Dimension size = helper.performIgnoreException(() -> element.getSize());
  
  tap(point.getX() + size.getWidth() / 2, point.getY() + size.getHeight() / 2);
}

相关文章