question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Appium 1.7.1][XCUITest][iOS]Wrong locations being clicked in WebView.

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
dilip16jcommented, Nov 6, 2017

Can we expect the fix in appium 1.7.2?when is the 1.7.2 release?

0reactions
lock[bot]commented, Apr 24, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A web element is seemingly clicked but in ... - Appium Discuss
When I navigate to a web page and click on a web element then no errors occur, ... HTML code is “transferred” into...
Read more >
Clicking on webview element executed but nothing happens ...
Verdict: the element cannot be recognised in the native context; Getting the element location and performing click on that location
Read more >
Webview access in android appium automation - Support
I am using the following code to access the webview but it always returns NATIVE_APP. Am I missing anything. Any suggestions are appreciated....
Read more >
How to Identify WebView Elements in Android Hybrid App?
Hi , We can't identify WebView elements by using UIAutomatorViewer insdie Android Sdk. Appium Inspector is unable to capture the device screen in...
Read more >
A web element is seemingly clicked but in ... - Appium Discuss
I am having the same problem, is it possible to do this using ruby and appium? Can a jquery command be passed in?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found