Skip to content

Commit fc13388

Browse files
committed
getCenter() method
1 parent a75e06d commit fc13388

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/java/io/appium/java_client/MobileElement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import com.google.common.collect.ImmutableMap;
2121
import org.openqa.selenium.By;
22+
import org.openqa.selenium.Dimension;
23+
import org.openqa.selenium.Point;
2224
import org.openqa.selenium.WebElement;
2325
import org.openqa.selenium.remote.*;
2426

@@ -68,6 +70,12 @@ public void setValue(String value) {
6870
execute(MobileCommand.SET_VALUE, builder.build());
6971
}
7072

73+
public Point getCenter() {
74+
Point upperLeft = this.getLocation();
75+
Dimension dimensions = this.getSize();
76+
return new Point(upperLeft.getX() + dimensions.getWidth()/2, upperLeft.getY() + dimensions.getHeight()/2);
77+
}
78+
7179
protected Response execute(String command, Map<String, ?> parameters) {
7280
return parent.execute(command, parameters);
7381
}

0 commit comments

Comments
 (0)