[Appium 1.7.1][XCUITest][iOS]Wrong locations being clicked in WebView.
See original GitHub issueThe problem
When calling WebElement.click() or setValue() on an Element, wrong location is being clicked, seems to be always below the element, i.e. Y axis problem. It happens to around half of the elements, some work, some don’t The app being tested is a web app built in Ionic.
Environment
- Appium version (or git revision) that exhibits the issue: Appium 1.7.1
- Last Appium version that did not exhibit the issue (if applicable): –
- Desktop OS/version used to run Appium: macOS Sierra 10.12.6
- Node.js version (unless using Appium.app|exe): 8.5.0
- Mobile platform/version under test: iOS 11 and iOs 10.3.3, both exhibit the same issue
- Real device or emulator/simulator: Real Device
- Appium CLI or Appium.app|exe: Appium CLI
Details
I will describe the issue using a profile button(dash-profile
in the logs) in our app as an example.
I have a test case where I call profileBUtton.click() while in WebView context, the area being clicked is below the profileBUtton. So Y axis translation seems to be wonky, X axis doesn’t seem to be exhibiting any issues. Capability NativeWebTap is set to true, false seems to be worse in terms of coordinate mismatch.
My workarounds to the issue are as follows: In my java client, instead of calling element.click(), i wrote a method Iclick(element):
public void Iclick(WebElement element) {
Point p = element.getLocation();
int x = p.getX();
int y = p.getY();
Dimension dim = element.getSize();
x = x + (dim.getWidth()/2);
y = y + (dim.getHeight()/2);
IOSDriver<?> driver1 = (IOSDriver)driver;
Actions actions = new Actions(driver1);
actions.moveToElement(element,dim.getWidth()/2,dim.getHeight()/2).perform();
driver1.tap(1,x,y, 1);
}
This seems to work perfectly and gets rid of all issues for me, but is not very robust in terms of using it long-term in an automation framework. Since we’d have to do testing differently for iOS and Android and split our pages.
I have modified the broken coords if statment in web.js [translateWebCoords case 20], to always show the y ratio calculated, and it’s always around .083 while x always stays at 1, so the y ratio seems to be causing the problems. Any idea why those offsets are applied to webviews on y axis? There’s urlBar offset even though many webviews do not have url bars. And other, seemingly arbitrary/hardcoded offsets too.
The second solution that works is modifying web.js file in xcuitest ios driver build folder. I basically just return coords instead of newCoords in [translateWebCoords case 20] and everything works fine.
The latter solution is pretty crude, since I was just commenting stuff out and seeing what works. If anyone could give me any info about the root cause and its fix I’d appreciate it.
Link to Appium logs
https://gist.github.com/JackGarbiec/df91f6721cdab818c0d4af4816b6dbec Logs without and with modified web.js,
if (newCoords.y === null) {
_logger2['default'].debug('Converted coordinates broken: ' + newCoords);
_logger2['default'].debug(' rect: ' + rect);
_logger2['default'].debug(' wvPos: ' + wvPos);
_logger2['default'].debug(' realDims: ' + realDims);
_logger2['default'].debug(' wvDims: ' + wvDims);
_logger2['default'].debug(' xRatio: ' + xRatio);
_logger2['default'].debug(' yRatio: ' + yRatio);
_logger2['default'].debug(' yOffset: ' + yOffset);
}
changed to
_logger2['default'].debug(' rect: ' + rect);
_logger2['default'].debug(' wvPos: ' + wvPos);
_logger2['default'].debug(' realDims: ' + realDims);
_logger2['default'].debug(' wvDims: ' + wvDims);
_logger2['default'].debug(' xRatio: ' + xRatio);
_logger2['default'].debug(' yRatio: ' + yRatio);
_logger2['default'].debug(' yOffset: ' + yOffset);
to debug the ratios and offsets.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Can we expect the fix in appium 1.7.2?when is the 1.7.2 release?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.