Unable to identify element with content-desc attribute from UI Automator Viewer, tried so many possibilities

Hi all,

I am having hard time locating the button with content-desc as “Sign Out”
I have tried below codes none of them seems to work :frowning:

1.driver.findElementByAndroidUIAutomator(“new UiSelector().text(“Sign Out”)”).click();
2.driver.findElementByAndroidUIAutomator(“UiSelector().description(“Sign Out”)”).click();
3.driver.findElementByAndroidUIAutomator(“text(“Sign Out”)”).click();
4.driver.findElementsByAndroidUIAutomator(“content-desc(“Sign Out”)”);
5. driver.findElementByXPath("//android.widget.Button[@content-desc=‘Sign Out’]").click();

Are you able to locate Change Pin ?If yes you can try with following sibling of Change Pin.

1 Like

Hi Jayesh, I am getting the same error as Sign Out,it doesnt identify element. Is there any difference in coding compared to hybrid vs native app. This is a native app

driver.findElement(By.xpath("//android.widget.Button[@content-desc=‘Sign Out’]")).

try this

Hi S10v10s , I have tried that earlier , didn’t work. I have put the combinations that I tried in my first post

are u able to click with other parameters or u r facing same issue with all

Make sure element is visible try to put some delay @nelson

I put thread.sleep for 10 seconds and got error again

Exception in thread “main” org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //android.widget.Button[@content-desc=‘Sign Out’] because of the following error:
SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘//android.widget.Button[@content-desc=‘Sign Out’]’ is not a valid XPath expression.

//*[@content-desc=‘Sign Out’]

make sure u re-edit single quote for sign out in your code. @nelson

tried ,getting this error
Exception in thread “main” org.openqa.selenium.WebDriverException: unknown error: Unsupported locator strategy: -android uiautomator
(Session info: chrome=59.0.3071.125)

I didn’t get you. Could you rephrase

Can you print the pagesource and check if Sign Out button is present ?

Yes, some times element hierarchy you will see in uiautomator it will different from page source values.

Give thread.sleep(3000) and then try.

I meant to say are u putting correct single quotes in the code. like this " ’ "

Try this
    driver.findElementByAndroidUIAutomator("UiSelector().description(\"Sign Out\")")
    In xpath, use index and content desc. sometimes 1 field may not identify.

Write some relative xpath like using following sibling or preceding sibling
or any other xpath functions

//[@content-desc=‘Change PIN’]/following::[1]