Find element by class-name and content-desc in web context selenium
<p>I am trying to write a test case using selenium Java for a mobile app in Android device.I have to find an element which in web view of mobile application.I have inspect the application using Appium inspect window and get the element details as below.</p>

<p>index: 65</p>

<p>text: </p>

<p>class: android.widget.Button</p>

<p>content-desc: Take New Photo</p>

<p>package: com.abc.xyz</p>

<p>resource id:</p>

<p>checkable: false</p>

<p>checked: false</p>

<p>clickable: true</p>

<p>enabled: true</p>

<p>focusable: true</p>

<p>focused: false</p>

<p>scrollable: false</p>

<p>long-clickable: false</p>

<p>is password: false</p>

<p>selected: false</p>

<p>And I have util method to switch window from native view to we view.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>public class Context {
 public void switchContextToWebView(AppiumDriver&lt;WebElement&gt; driver)
   throws InterruptedException {
  Thread.sleep(Constants.DEFAULT_TIMEOUT);
  Set&lt;String&gt; contextNames = driver.getContextHandles();
  for (String contextName : contextNames) {
   if (contextName.contains("WEBVIEW")) {
    driver.context(contextName);
   }
  }

 }

 public void switchContextToNativeView(AppiumDriver&lt;WebElement&gt; driver)
   throws InterruptedException {
  Thread.sleep(Constants.DEFAULT_TIMEOUT);
  Set&lt;String&gt; contextNames = driver.getContextHandles();
  for (String contextName : contextNames) {
   if (contextName.contains("NATIVE")) {
    driver.context(contextName);
   }
  }

 }
}</code></pre>
</div>
</div>
</p>

<p>And in my test class I try to find this element by using below codes.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>Context context = new Context();
  context.switchContextToWebView(driver);
  //WebElement pickCameraOption = driver.findElement(By.className("android.widget.Button"));
  WebElement elem = driver.findElementByXPath("//android.widget.Button[@content-desc='Take New Photo']");
  //WebElement elem = driver.findElementByXPath("//*[@class='android.widget.Button'and @content-desc='Take New Photo']");
  wait.until(ExpectedConditions.visibilityOf(elem));
  
  elem.click();</code></pre>
</div>
</div>
</p>

<p>You can observe I have tried two ways to get this work done.But they are not working for me.</p>

<p>Can anyone help me to figure out the exact issue with this selenium finders?</p>