Skip to content
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

findElementFromElement not returning child element #10101

Closed
tfcardoso opened this issue Jan 30, 2018 · 14 comments
Closed

findElementFromElement not returning child element #10101

tfcardoso opened this issue Jan 30, 2018 · 14 comments
Labels
Needs Info typically non-actionable; needs author to respond ThirdParty upstream problems XCUITest regarding xcuitest driver

Comments

@tfcardoso
Copy link

The problem

After I upgraded to Xcode9, iOS11 and Appium v1.7.2 several of the nested find elements that worked before stopped working.

Environment

  • Appium version (or git revision) that exhibits the issue: v1.7.2 / XCode9.2
  • Last Appium version that did not exhibit the issue (if applicable): 1.7.1 / XCode8.3.3 / iOS10.3.3
  • Mobile platform/version under test: iOS 11.2.5
  • Real device or emulator/simulator: Real Device
  • Appium CLI or Appium.app|exe: v1.7.2

Details

The project I test its quite complex, so I often use findElementByIosNsPredicate that gives me more freedom on my queries. After I updated to XCode9, iOS11 the queries that find element from a parent element started failing. Strangely enough if I query for elements instead of element, the first returns properly while the second doesn't find the element.

Link to Appium logs

https://gist.github.com/tfcardoso/f57cae4cf183c8eed120eafc326477f3

Code To Reproduce Issue [ Good To Have ]

I made an example based on the following view:
https://image.prntscr.com/image/nr0Bv3wDRRyh-p2vK2Jshg.png

Its a XCUIElementTypeCollectionView with several XCUIElementTypeCell and inside the penultimate one, there is an element that has a play button (with id/name chatView_fileTransfers_button_videoPlay).

IOSElement parentElement = (IOSElement) ((IOSDriver) driver).findElementByIosNsPredicate("(type = \"XCUIElementTypeCollectionView\")");
List<MobileElement> rows = parentElement.findElementsByIosNsPredicate("(type = \"XCUIElementTypeCell\")");
MobileElement cellElement = rows.get(rows.size() - 2);
System.out.println("I'm " + cellElement.getAttribute("name"));
List<MobileElement> videoButtons = cellElement.findElementsById("chatView_fileTransfers_button_videoPlay");
System.out.println("Amount of elements :"+videoButtons.size());
try {
     cellElement.findElementById("chatView_fileTransfers_button_videoPlay");
} catch (Exception e) {
     System.out.println("Element not found");
}

The output from the above code is:

I'm WMCIncomingFileTransferCell
Amount of elements :1
Element not found

There is other person with apparently the same problem in http://discuss.appium.io/t/appium-ios-findelementfromelement-is-not-working/20727

@mykola-mokhnach
Copy link
Collaborator

Is this button found if you execute find in the global context (driver.findElement) ?

@mykola-mokhnach mykola-mokhnach added Needs Info typically non-actionable; needs author to respond ThirdParty upstream problems XCUITest regarding xcuitest driver labels Jan 30, 2018
@tfcardoso
Copy link
Author

Is this button found if you execute find in the global context (driver.findElement) ?

Yes, it is found.

@mykola-mokhnach
Copy link
Collaborator

The only diff I see there is the usage of firstMatch API. Try to comment out this condition in your local WDA source and check if it helps.

@tfcardoso
Copy link
Author

I had to revert xcode, because I have urgent deliveries, so I may try that only in couple days. In the meantime @bhagarenikhi can you try and comment that condition and re-run your tests?

@bhagarenikhi
Copy link

bhagarenikhi commented Jan 30, 2018

Yes. I have tried by commenting the condition but no luck :-(.
@mykola-mokhnach, This case is happened only when you try to locate the parent element by find_elements method.

cell = $driver.find_elements(:name, 'locationCell').first
cell.find_element(:name, 'title')
Above code is not working. While below code works fine.
cell = $driver.find_element(:name, 'locationCell')
cell.find_element(:name, 'title')

@mykola-mokhnach
Copy link
Collaborator

mykola-mokhnach commented Jan 30, 2018

I assume it's some internal XCTest magic. I'd try to use single class chain locator instead to workaround this problem. For example, the described case might use the following chain locator:

**/XCUIElementTypeCollectionView/XCUIElementTypeCell[-2]/**/XCUIElementTypeButton[`name == 'chatView_fileTransfers_button_videoPlay'`]

@newthomas
Copy link

newthomas commented Jan 31, 2018

I have the same problem. First I thought it was Appium 1.8.0 but then I see the same issue with 1.7.2.

Previously this was used:
return findElements(By.id(cellId)).get(cellIndex).findElement(By.id(elementId))

My very ugly workaround:
return findElements(By.id(cellId)).get(cellIndex).findElements(By.id(elementId)).get(0)

Which tells me, that

cell = driver.findElement(...)
cell.findElement(...)

and

cell = driver.findElements(...).get(index)
cell.findElements(...).get(index)

work, but not:

cell = driver.findElements(...).get(index)
cell.findElement(...)

@jamesvanhorn
Copy link

You can roll back to appium 1.7.1 and it should work fine, if there isn't anything specific in 1.7.2 that you rely on. npm i -g appium@1.7.1

@newthomas
Copy link

newthomas commented Feb 1, 2018

Works for me with:

  • Appium version: v1.7.1 / XCode 9.2
  • Mobile platform/version under test: iOS 11.2 (iPhone 8 Simulator)

@tfcardoso
Copy link
Author

@mykola-mokhnach

The only diff I see there is the usage of firstMatch API. Try to comment out this condition in your local WDA source and check if it helps.

I upgraded again to Xcode9.2. Tested again to see if it continued failing, and then with the code:

if (FBShouldUseFirstMatchSelector) {
    XCUIElement* result = self.firstMatch;
    return result.exists ? result : nil;
  }

commented it works 🥇

You think a fix can be made?

@mykola-mokhnach
Copy link
Collaborator

Thanks for checking @tfcardoso. I've created a PR to patch it, so firstMatch will only be executed in application context

@newthomas
Copy link

Confirm: no issues with Appium 1.8.0-beta3.

@bowka
Copy link

bowka commented Mar 25, 2019

It doesn't work for me on version 1.9.2
actually I've tried multiple versions but each version has some issues
1.8.0 grandPermissions issues
1.9.1 set location issue
1.7.2 findElementFromElement issue
Anybody who still facing the issue after updating to new version?

@lock
Copy link

lock bot commented Mar 27, 2020

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.

@lock lock bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Info typically non-actionable; needs author to respond ThirdParty upstream problems XCUITest regarding xcuitest driver
Projects
None yet
Development

No branches or pull requests

6 participants