本文整理汇总了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)
{
}
}
示例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);
}
示例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();
}
}
}
示例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);
}
}
示例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();
}
}
示例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());
}