How to get 'content-desc' attribute value

Hi

In my application, I have to get value of attribute ‘content-desc’ and then I have to apply assertions for this value.

I am using following

String desc = LaunchApplication.driver.findElement(By.xpath("//android.view.View[@index=‘5’]")).getAttribute(“content-desc”).toString();

But this neither returns me exception. But my test fails and I didn’t get value.

Can you please help me on this.

can u try with getText()?

Try This:

driver.findelement(By.id(“id”)).getAttribute(“name”)

  1. The element you want to interact with is inside the web view
  2. You haven’t switched to the web view.

I can see that you are able to locate the element, however if you switch to web view, it will get easier to interact with.

@Priyank_Shah can you correct me if I’m wrong. I may have missed something as I haven’t faced this kind of issue.

@pr4bh4sh, there is no further requirement but i assume application code has enable web view debug option. and i think once you switch to web view, you can interact with any element just like web application.

Thanks and you are correct. If the element is visible in UI Automator switching is not needed but it’s better if we switch for the better interaction.

Actually switching is needed because when u print driver.getPageSource() before and after you come to know difference. And I do not trust UIAUtomator When web view comes in picture.

1 Like

Try this it works :
@AndroidFindBy(uiAutomator = “new UiSelector().description(“Please enter password”)”)
private AndroidElement myElement;

1 Like

None of the below is working for me. getting null value though value is available for content-desc attribute. Any solution?

.getAttribute(“content-desc”)
getText()
getAttribute(“contentDescription”)
getAttribute(“name”)