You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@AndroidFindBy and @iOSFindBy for native app automation #184
Hi!
They are designed generally for native apps. Please provide the detailed report of the problem that you've found. Stacktraces, locators, code samples etc. What locators do you use? What java_client version/server version? Below examples that work against native app:
@FindBy(css = "someBrowserCss") //this locator is used when here is browser (desktop or mobile) @iOSFindBy(uiAutomator = ".elements()[0]") //this locator is used when here is iOS native content @AndroidFindBy(className = "android.widget.TextView") //this locator is used when here is Android //native content publicList<WebElement> androidOriOsTextViews;
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/text1\")")
publicList<WebElement> androidUIAutomatorViews;
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/text1\")")
publicList<MobileElement> mobileElementViews; //Also with Appium page object tools it is //possible to declare RemoteWebElement or any MobileElement subclass @FindBy(className = "android.widget.TextView")
publicList<MobileElement> mobiletextVieWs;
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/text1\")")
publicList<RemoteWebElement> remoteElementViews;
@AndroidFindBy(id = "android:id/text1")
publicWebElementtextView;
Sure, I'm getting the data that I have right now... Will edit this post in a minute.
Java client 2.2.0. I'm running it on a highly customized spring+cucumber jvm framework but I reproduced it on regular cucumber jvm as well. I'll try and reproduce it without cucumber as well.
Can you define the path to your app like this or that. Does it help?
Do you define the path to your app via Appium desktop UI? What Appium server version you use?
If I'm right then it is possible that your problem is related to appium/appium#4091. Given capabilities and capabilities that are defined in the server side via desktop UI are not merged. Then you have to define the path to app in Java code till it fixed.
So Appium page object tools attempt to handle it the way like here is mobile or desktop browser. Because there is no FindBy and iOS/AndroidFindBy are for apps it tries to locate the element using Id or name that supposed to be equal to field name.
org.openqa.selenium.NoSuchElementException: Can't locate an element by this strategy: by id or name "iosButton"
Fordocumentationonthiserror, pleasevisit: http://seleniumhq.org/exceptions/no_such_element.htmlBuildinfo: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'Systeminfo: host: 'Mac-Admin.local', ip: '192.168.42.129', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.8.0_25'
It think the root cause has been described in referred issue appium/appium#4091. The workaround in my previous message.
Sorry for late response - The reason I'm not specifying an app capability is because I have the app pre-installed with ideviceinstaller. I use bundleId and udid to run the tests.
Ideally I do not want the app installed using appium at all.
I'd keep it open until I find a resolution, as it's still a problem for me. Once I find a solution, I'll update this ticket (for future reference if someone encounters the same issue) and close it then.
Ok. I think the app should be calculated on the server-side and returned in capabilities (in your case). What do you think about this feature? If you find this cool and appium/appium#4091 is not relevant please open a new issue here: https://github.com/appium/appium/issues
Also I'll try to find another way to detect what is it right now - an app or browser.
@Simon-Kaz you can review this. You can clone master, build it locally and try to reproduce... If you want :) The choice of By is smarter now and depends on the current context (when NATIVE_APP then it uses locators defined via AndroidFindBy/iOSFindBy and default Selenium FindBy otherwise)
Instead of using the supplied accessibility identifier to locate elements, PageFactory.initElements is attempting to use the property name as the identifier.
It's behaving as if the annotation doesn't exist and is defaulting to use the page object property name.
Any one knows how to define an xpath that contains specific id and text using @AndroidFindBy
this is the element :
driver.findElement(By.xpath("//android.widget.TextView[contains(@resource-id,'com.sec.android.app.music:id/tab_text') and @text='TRACKS']"))
i tried to add it in that way :
@AndroidFindBy(xpath = ""//android.widget.TextView[contains(@resource-id,'com.sec.android.app.music:id/tab_text') and @text='TRACKS']"")
private WebElement TrackList;
but didnt work and shows me this message :
org.openqa.selenium.NoSuchElementException: Can't locate an element by this strategy: By.chained({By.xpath: "//android.widget.TextView[contains(@resource-id ='com.sec.android.app.music:id/tab_text') and @text='TRACKS']"})
Activity
TikhomirovSergey commentedon Apr 15, 2015
Hi!
They are designed generally for native apps. Please provide the detailed report of the problem that you've found. Stacktraces, locators, code samples etc. What locators do you use? What java_client version/server version? Below examples that work against native app:
Full samples:
Android 1
Android 2
Android 3
iOS
About interface. Actually it exists. MobileDriver. There is new extended version that probably will be merged.
Simon-Kaz commentedon Apr 23, 2015
@TikhomirovSergey I'm having issues with the following annotation:
@iOSFindBy(accessibility = "Tracker")
private MobileElement trackerButton;
When i use it, the following shows up in the the appium logs:
au.getElementsById('trackerButton')
au.getElementsByName('trackerButton')
au.getElementsByAccessibilityId('trackerButton')
It looks like the annotation is not passing the selector?
EDIT: I've just tried changing the "accessibility" to "name", and it's the same.
TikhomirovSergey commentedon Apr 23, 2015
Hi @Simon-Kaz
It is interesting. Is it browser test?
Simon-Kaz commentedon Apr 23, 2015
Native app.
TikhomirovSergey commentedon Apr 23, 2015
Ok. I will try to repaet this today.
What java_client version you use? It will be nice if you provide capabilities that you use.
Simon-Kaz commentedon Apr 23, 2015
Sure, I'm getting the data that I have right now... Will edit this post in a minute.
Java client 2.2.0. I'm running it on a highly customized spring+cucumber jvm framework but I reproduced it on regular cucumber jvm as well. I'll try and reproduce it without cucumber as well.
TikhomirovSergey commentedon Apr 23, 2015
...and... I've forgotten to ask. Does this find the wrong element or throw the NoSuchElementException?
Simon-Kaz commentedon Apr 23, 2015
No such element exception, as there's no element with that name/id/label.
Simon-Kaz commentedon Apr 23, 2015
OK it works outside of my project, guess I'll have to do some digging and find out why the annotation is not working :(
TikhomirovSergey commentedon Apr 23, 2015
Can you define the path to your app like this or that. Does it help?
Do you define the path to your app via Appium desktop UI? What Appium server version you use?
TikhomirovSergey commentedon Apr 23, 2015
If I'm right then it is possible that your problem is related to appium/appium#4091. Given capabilities and capabilities that are defined in the server side via desktop UI are not merged. Then you have to define the path to app in Java code till it fixed.
TikhomirovSergey commentedon Apr 23, 2015
@Simon-Kaz @email2vimalraj
It seems I'm right. Please look below.
Here are settings:

The code:

The command
returns
So Appium page object tools attempt to handle it the way like here is mobile or desktop browser. Because there is no FindBy and iOS/AndroidFindBy are for apps it tries to locate the element using Id or name that supposed to be equal to field name.
It think the root cause has been described in referred issue appium/appium#4091. The workaround in my previous message.
Simon-Kaz commentedon Apr 24, 2015
Sorry for late response - The reason I'm not specifying an app capability is because I have the app pre-installed with ideviceinstaller. I use bundleId and udid to run the tests.
Ideally I do not want the app installed using appium at all.
Simon-Kaz commentedon Apr 24, 2015
I'd keep it open until I find a resolution, as it's still a problem for me. Once I find a solution, I'll update this ticket (for future reference if someone encounters the same issue) and close it then.
TikhomirovSergey commentedon Apr 24, 2015
Ok. I think the app should be calculated on the server-side and returned in capabilities (in your case). What do you think about this feature? If you find this cool and appium/appium#4091 is not relevant please open a new issue here: https://github.com/appium/appium/issues
Also I'll try to find another way to detect what is it right now - an app or browser.
5 remaining items
Simon-Kaz commentedon Apr 28, 2015
I see it's been merged, that's great, thanks! Anything else that you need me to do? I can try and reproduce the issue with latest build of Appium.
TikhomirovSergey commentedon Apr 28, 2015
@Simon-Kaz you can review this. You can clone master, build it locally and try to reproduce... If you want :) The choice of By is smarter now and depends on the current context (when NATIVE_APP then it uses locators defined via AndroidFindBy/iOSFindBy and default Selenium FindBy otherwise)
justintilson commentedon Jun 30, 2015
I'm getting a similar issue as @Simon-Kaz. I tried versions 2.2.0 and 3.0.0 with the same result.
Here is the constructor:
and a sample property from one of my page objects:
and a screenshot from my debugger:
Instead of using the supplied accessibility identifier to locate elements, PageFactory.initElements is attempting to use the property name as the identifier.
It's behaving as if the annotation doesn't exist and is defaulting to use the page object property name.
Am I missing something?
Merge pull request #213 from TikhomirovSergey/#211_#184-fix
tomb50 commentedon Jul 31, 2015
This issue looks to still persist even with the fixes introduced with v3.1.0 which has the above, I am running against Appium 1.4.8 (no GUI app).
@IOSFindBy(accessibility = "123)
public WebElement abc
Is still trying to find using the instance variable value and not "123".
Please let me know if any additional info is required.
tomb50 commentedon Jul 31, 2015
Just to confirm, the CONTEXT is NATIVE_APP and Desired Capabilities are the same as previous posters, the App is specified.
tomb50 commentedon Jul 31, 2015
Disregard my comments, I was an idiot and was passing the driver directly into PageFactory.initElements() rather than a new AppiumFieldDecorator.
robintel commentedon Nov 23, 2017
@tomb50
Hello,
It is unclear to me how you fixed it. Can you give some more details?
Thanks,
Robin
nttrazvan commentedon Nov 24, 2017
Hello @tomb50 ,
Could you please provide a more detailed solution to this, I'm facing the same issue.
Razvan
vikramvi commentedon Dec 12, 2017
@robintel @nttrazvan can you please check appium/appium#9780 and add your comments as well.
It's always better to create new issue than commenting on closed one.
ppzzss commentedon May 3, 2018
Below annotations work well in Appium 1.7.2
@iOSXCUITFindBy (xpath = "xxxx")
@AndroidFindBy (id = "bbbb")
public WebElement usernameTextField;
ppzzss commentedon May 3, 2018
with Java_client 5.0.4
amrsa1 commentedon Mar 27, 2019
Any one knows how to define an xpath that contains specific id and text using @AndroidFindBy
this is the element :
driver.findElement(By.xpath("//android.widget.TextView[contains(@resource-id,'com.sec.android.app.music:id/tab_text') and @text='TRACKS']"))
i tried to add it in that way :
@AndroidFindBy(xpath = ""//android.widget.TextView[contains(@resource-id,'com.sec.android.app.music:id/tab_text') and @text='TRACKS']"")
private WebElement TrackList;
but didnt work and shows me this message :
org.openqa.selenium.NoSuchElementException: Can't locate an element by this strategy: By.chained({By.xpath: "//android.widget.TextView[contains(@resource-id ='com.sec.android.app.music:id/tab_text') and @text='TRACKS']"})
adityabhargav commentedon Aug 14, 2019
Answer :-
trackerButton - is similar to "driver.findElement(By.Id("Tracker"))"
need to give like
trackerButton.Click();
Note:- trackerButton is not alone a mobile element , it carries property of "driver.findElement(By.Id("Tracker"))".