int webPageWidth = getInspector().getInnerWidth();
if (dim.getWidth() != webPageWidth) {
log.fine("BUG : dim.getWidth()!=webPageWidth");
}
Criteria c = new TypeCriteria(UIAWebView.class);
String json = c.stringify().toString();
StringBuilder script = new StringBuilder();
script.append("var root = UIAutomation.cache.get('1');");
script.append("var webview = root.element(-1," + json + ");");
script.append("var webviewSize = webview.rect();");
script.append("var ratioX = 1.0 * webviewSize.size.width / " + dim.getWidth() + ";");
script.append("var ratioY = 1.0 * webviewSize.size.height / " + dim.getHeight() + ";");
int top = po.getY();
int left = po.getX();
// switch +1 to +2 in next, with +1 some clicks in text fields didn't bring up the
// keyboard, the text field would get focus, but the keyboard would not launch
// also with this change 17 miscellaneous selenium tests got fixed
switch (position) {
case TOP_LEFT: {
script.append("var top = (" + top + "*ratioX);");
script.append("var left = (" + left + "*ratioY);");
break;
}
case CENTER: {
Dimension size = getSize();
script.append("var top = (" + top + " + " + size.getHeight() + " / 2) * ratioX;");
script.append("var left = (" + left + " + " + size.getWidth() + " / 2) * ratioY;");
break;
}
}
script.append("var x = left;");
boolean ipad = session.getCapabilities().getDevice() == DeviceType.ipad;
boolean ios7 = new IOSVersion(session.getCapabilities().getSDKVersion()).isGreaterOrEqualTo("7.0");
boolean ios8 = new IOSVersion(session.getCapabilities().getSDKVersion()).isGreaterOrEqualTo("8.0");
if (ios8) {
if (isSafari()) {
// the first button in the second view for iOS8 safari is the height of the address bar
script.append("top += root.elements()[1].elements()[0].rect().size.height;");
}
script.append("var y = top;");
} else if (ios7) {
script.append("var y = webviewSize.origin.y + top;");
if (isSafari()) {
script.append("var orientation = UIATarget.localTarget().deviceOrientation();");
script.append("var plus = orientation == UIA_DEVICE_ORIENTATION_LANDSCAPELEFT || orientation == UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN;");
// TODO: why is the webView shifted by 20
script.append("y += plus? 20 : -20;");
}
} else {
if (isSafari()) {
if (ipad) {
// for ipad, the adress bar h is fixed @ 96px.
script.append("var y = top+96;");
} else {
ImmutableList<ContentResult> results =
session.getApplication().getCurrentDictionary().getPotentialMatches("Address");
if (results.size() != 1) {
log.warning("translation returned " + results.size());
}
ContentResult result = results.get(0);
String addressL10ned = result.getL10nFormatted();
Criteria
c2 =
new AndCriteria(new TypeCriteria(UIAElement.class), new NameCriteria(addressL10ned),
new LabelCriteria(addressL10ned));
script.append("var addressBar = root.element(-1," + c2.stringify().toString() + ");");
script.append("var addressBarSize = addressBar.rect();");
script.append("var delta = addressBarSize.origin.y +39;");
script.append("if (delta<20){delta=20;};");
script.append("var y = top+delta;");
}
} else {
Criteria wv = new TypeCriteria(UIAScrollView.class);
script.append("var webview = root.element(-1," + wv.stringify().toString() + ");");
script.append("var size = webview.rect();");
script.append("var offsetY = size.origin.y;");
// UIAWebView.y
script.append("var y = top+offsetY;");
//script.append("var y = top+64;");