当前位置: 首页>>代码示例>>Java>>正文


Java WebElement.getLocation方法代码示例

本文整理汇总了Java中org.openqa.selenium.WebElement.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Java WebElement.getLocation方法的具体用法?Java WebElement.getLocation怎么用?Java WebElement.getLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openqa.selenium.WebElement的用法示例。


在下文中一共展示了WebElement.getLocation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mark

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public void mark(WebElement ele, File file) throws IOException
{
	BufferedImage bufImg = ImageIO.read(file);
	
	try
	{
		WebElement webEle = (WebElement) ele;
		Point loc = webEle.getLocation();
		Dimension size = webEle.getSize();
		
		Graphics2D g = bufImg.createGraphics();
		g.setColor(Color.red);
		g.drawRect(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
	}
	catch(StaleElementReferenceException se)
	{
	}
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:20,代码来源:TargetElementMark.java

示例2: getLocation

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void getLocation() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    Point location = element1.getLocation();
    java.awt.Point p = EventQueueWait.call(button, "getLocation");
    AssertJUnit.assertEquals(p.x, location.x);
    AssertJUnit.assertEquals(p.y, location.y);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:15,代码来源:JavaDriverTest.java

示例3: hover

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public void hover(Element ele)
{
	WebElement webEle = searchStrategyUtils.findStrategy(WebElement.class, ele).search(ele);
	if(webEle == null)
	{
		logger.warn("can not found element.");
		return;
	}
	
	if(!(ele instanceof FileUpload))
	{
		Dimension size = webEle.getSize();
		Point loc = webEle.getLocation();
		int toolbarHeight = engine.getToolbarHeight();
		int x = size.getWidth() / 2 + loc.getX();
		int y = size.getHeight() / 2 + loc.getY() + toolbarHeight;
		
		try
		{
			new Robot().mouseMove(x, y);
		}
		catch (AWTException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:30,代码来源:SeleniumHover.java

示例4: scrollTo

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Scroll to element (at the center of the screen)
 *
 * @return this mobile element which allows chained actions
 */
@SuppressWarnings( "unchecked")
@PublicAtsApi
public T scrollTo() {

    try {

        if (MobileElementFinder.getElementContext(this).toUpperCase().startsWith("WEBVIEW")) {

            // in WEBVIEWs the target element exists, while in the NATIVE context it doesn't until we scroll to it
            new MobileElementState(this).waitToBecomeExisting();

            Dimension screenDimensions = ((MobileDriver) getUiDriver()).getScreenDimensions();
            WebElement element = MobileElementFinder.findElement(appiumDriver, this);

            // window.scrollTo(0, element.getLocation().y);    -->  will scroll the element to top-left

            int scrollToY = 0;
            int screenCenter = screenDimensions.getHeight() / 2 + element.getSize().height / 2;
            if (element.getLocation().y < screenCenter) {
                // the element is located after the screen center if we scroll to (0, element.getLocation().y)
                // because it is near the bottom of the application => we can't center it, but it is OK on that position
                scrollToY = element.getLocation().y;
            } else {
                scrollToY = element.getLocation().y - screenCenter;
            }

            ((JavascriptExecutor) appiumDriver).executeScript("window.scrollTo(0," + scrollToY + ")");
        } else {

            if (getElementProperty("name") != null) {
                appiumDriver.scrollTo(getElementProperty("name")); // only works for NATIVE context
            }
        }

        return (T) this;
    } catch (Exception e) {
        throw new MobileOperationException(this, "scrollTo", e);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:45,代码来源:MobileElement.java

示例5: takeStatusScreenshot

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public static void takeStatusScreenshot(Status status, MongoDatabase mongoDatabase, WebDriver driver) {
    long id = status.getId();
    User user = status.getUser();
    try {
        // visit the twitter url
        driver.get(TWITTER_BASE_URL + user.getScreenName() + "/status/" + id);

        WebDriverWait webDriverWait = new WebDriverWait(driver, 4);
        webDriverWait.until(
                ExpectedConditions.visibilityOfElementLocated(
                        By.cssSelector(PERMALINK_TWEET_CONTAINER)));

        // Find the tweet container
        WebElement element = driver.findElement(By.cssSelector(PERMALINK_TWEET_CONTAINER));

        // take a full screenshot
        File screenshotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

        // create in memory image data
        BufferedImage screenshotImage = ImageIO.read(screenshotFile);

        // calculate the position of the tweet element
        Point point = element.getLocation();
        int elementWidth = element.getSize().getWidth();
        int elementHeight = element.getSize().getHeight();

        // crop to get only the container of the tweet itself (sometimes this doesn't work on mac)
        BufferedImage elementScreenshotImage =
                screenshotImage.getSubimage(
                        point.getX() + 4,
                        point.getY() + 4,
                        elementWidth - 4,
                        screenshotImage.getHeight() < point.getY() + elementHeight
                                ? screenshotImage.getHeight() - 4
                                : elementHeight - 4);
        ImageIO.write(elementScreenshotImage, "png", screenshotFile);
        FileUtils.copyFile(screenshotFile, new File("screenshot/" + id + ".png"));
    } catch (Exception e) {
        saveFailureStatusProcesssed(mongoDatabase, id, false);
        System.out.println(
                String.format(
                        "Unable to create screenshot for %s with id: %d",
                        user.getScreenName(),
                        id));
        e.printStackTrace();
    }
}
 
开发者ID:nribeka,项目名称:twitter-stuff,代码行数:48,代码来源:StatusUtils.java

示例6: CreativeElement

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public CreativeElement(WebElement e){
    this.element = e;
    this.quad = new CyclicQuad(e.getLocation(), e.getSize().getHeight(), e.getSize().getWidth());
}
 
开发者ID:sethijatin,项目名称:creative-element,代码行数:5,代码来源:CreativeElement.java


注:本文中的org.openqa.selenium.WebElement.getLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。