New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: getPageSource() does not return all elements. #74

Closed
amedvedjev opened this Issue Jul 31, 2014 · 14 comments

Comments

Projects
None yet
8 participants
@amedvedjev
Copy link

amedvedjev commented Jul 31, 2014

Hi,

while trying to workaround "appium/appium#3222" i met with same issue, but now with "driver.getPageSource()".

I can find some elements By.Id with "driver.findElements" (or with android UIAutomator tool) but can't see it in "driver.getPageSource()".

I can share logs externally that subsequent:

  • driver.findElements(By.Id "someText") = success
  • driver.getPageSource -> search for "someText" = failed
  • driver.findElements(By.Id "someText") = success

Is there any workaround between these two issues?

in the mean time i am force to balance both two searches:

  • search driver.findElements(By.Id "someText")
  • or search inside driver.getPageSource -> get element bounds attribute -> tap element with driver.tap(1,x,y,200)

or

  • vice versa
@jlipps

This comment has been minimized.

Copy link
Member

jlipps commented Jul 31, 2014

could this be a compression hierarchy issue @bootstraponline ?

@bootstraponline

This comment has been minimized.

Copy link
Member

bootstraponline commented Jul 31, 2014

yes, compression will result in elements not being returned

@Jonahss

This comment has been minimized.

Copy link
Contributor

Jonahss commented Aug 1, 2014

@amedvedjev what sort of element are you looking for? The xml returned by getPageSource() is compressed to remove some extraneous elements. http://developer.android.com/tools/help/uiautomator/UiDevice.html#setCompressedLayoutHeirarchy%28boolean%29

@amedvedjev

This comment has been minimized.

Copy link

amedvedjev commented Aug 1, 2014

well.

if i am able to find element By.Id with findElements() -> i believe it must be found also in raw search with getPagesource().

Is it?

Let now return to our example with code:

System.out.println(driver.findElements(backIcon_Locator));
System.out.println(driver.getPageSource());

Result of code execution:

[[[AppiumDriver: android on ANDROID (260c0a92-d657-4a8c-8f6a-538632db5ed7)] -> id: android:id/up]]
getPageSource see here: https://docs.google.com/file/d/0B1L_JAD2_USZRW0zRWUzcUw2N00/

where there is NO element with "android:id/up".

In the same time UI_Automator we can see all is correct:

see in link above

@bootstraponline

This comment has been minimized.

Copy link
Member

bootstraponline commented Aug 1, 2014

I think there's a bit of confusion. There are two types of page source. Compressed & uncompressed. If the id exists in the uncompressed and not in the compressed, then you'll be able to find it without seeing it in the source. Currently that's due to how xpath is implemented.

@amedvedjev

This comment has been minimized.

Copy link

amedvedjev commented Aug 1, 2014

hi,

  1. what is the reason of elements not visible in compressed source?
  2. is there any way e.g. in client to make element 100% present in compressed source?
  3. is there any way to get always uncompressed hierarchy with getPageSource() with java Appium client?

i see following in UI automator. is it possible to make it configurable with java client?

public void setCompressedLayoutHeirarchy (boolean compressed)

Enables or disables layout hierarchy compression. If compression is enabled, the layout hierarchy derived from the Acessibility framework will only contain nodes that are important for uiautomator testing. Any unnecessary surrounding layout nodes that make viewing and searching the hierarchy inefficient are removed.
Parameters
compressed true to enable compression; else, false to disable
Since

Android API Level 18
@takakim

This comment has been minimized.

Copy link

takakim commented Nov 3, 2014

Hi,
I'm getting similar problem, sometimes while running my tests the locator I use cannot find the element.
I also found this issue this seems to be related to this topic. https://code.google.com/p/android/issues/detail?id=69931
Beside, is there any update if this is really an issue from Appium, or uiautomator?

@Jonahss

This comment has been minimized.

Copy link
Contributor

Jonahss commented Nov 3, 2014

Looks like it's an issue with uiautomator, in which case there's not much we can do until it gets fixed :(

@ranbena

This comment has been minimized.

Copy link

ranbena commented Nov 26, 2014

Experiencing the same problem.
We've looked into this very thoroughly and realized that UiAutomator is to blame for the false negatives. A workaround we found is to restart the UiAutomator process and search for the element once again. 100% success rate.

Unfortunately, this can't be done with Appium because stopping the process - stops the test run. 😦 @bootstraponline @jlipps @Jonahss

Instead we utilize UiAutomator Python wrapper and restart it's server when needed. Finally, results are green.

@takakim @amedvedjev

@amirnissim

This comment has been minimized.

Copy link

amirnissim commented Nov 30, 2014

+1

@Jonahss

This comment has been minimized.

Copy link
Contributor

Jonahss commented Dec 1, 2014

Thanks @ranbena, that's really helpful advice. We actually have means to restart UIAutomator, and do it for some of our other operations.

I'm creating an issue for the appium repo to see if we can implement this workaround. Maybe we can reset UIAutomator when an element isn't found?

@Jonahss

This comment has been minimized.

Copy link
Contributor

Jonahss commented Dec 1, 2014

Feel free to chime in on the issue referenced above; I'm closing this issue because this is related to appium server not java-client.

@Jonahss Jonahss closed this Dec 1, 2014

@0x1mason

This comment has been minimized.

Copy link
Contributor

0x1mason commented Jan 8, 2015

@amedvedjev @amirnissim @takakim and others: I added a workaround to AppiumBootstrap.jar that resolves this behavior. appium/appium#4200

@amirnissim

This comment has been minimized.

Copy link

amirnissim commented Jan 10, 2015

great news! thanks @0x1mason 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment