title: How to find specific element within the iframe of electron app?
body: <p>I am using the code similar to this one <a href="https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-howto-find-ui-elements#finding-an-element-by-name" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-howto-find-ui-elements#finding-an-element-by-name</a>
  for getting specific element within a window and it doesn't work if my element is inside iframe which is inside electron app.</p>
  <p>However this changes if I run <a href="https://accessibilityinsights.io/" rel="nofollow noreferrer">insights</a> and manually inspect my electron application (Slack, Teams etc.). After that my code execution finds exact element within the iframe.</p>
  <p>EDIT:</p>
  <pre class="lang-cpp prettyprint-override"><code>int main(int argc, char *argv[])
  {
      HRESULT hr;
      int ret = 0;
      IUIAutomationElement *pTargetElement = NULL;
  
      CoInitializeEx(NULL, COINIT_MULTITHREADED);
  
      IUIAutomationElement *pRootElement;
  
      std::string elementName = &quot;Missed&quot;;
      CComBSTR temp(elementName.c_str());
  
      std::string inputWindowTitle = &quot;Microsoft Teams&quot;;
      CA2T wt (inputWindowTitle.c_str());
      HWND hwnd = ::FindWindow(NULL, wt);
  
      IUIAutomation *pAutomation = NULL;
      hr = CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation), (void **)&amp;pAutomation);
      if (FAILED(hr) || pAutomation == NULL)
      {
          ret = 1;
          goto cleanup;
      }
  
      PROPERTYID pPIDProperties[] = {UIA_BoundingRectanglePropertyId};
  
      IUIAutomationCondition *pCondition;
      VARIANT varProperty;
      VariantInit(&amp;varProperty);
      varProperty.vt = VT_BSTR;
      varProperty.bstrVal = temp;
  
      SetForegroundWindow(hwnd);
      SetFocus(hwnd);
      SetActiveWindow(hwnd);
      
      if (SUCCEEDED(pAutomation-&gt;ElementFromHandle(hwnd, &amp;pRootElement)))
      {
          if (SUCCEEDED(pAutomation-&gt;CreatePropertyCondition(UIA_NamePropertyId, varProperty, &amp;pCondition)))
          {
              if (SUCCEEDED(pRootElement-&gt;FindFirst(TreeScope_Descendants, pCondition, &amp;pTargetElement)))
              {
  
                  if (pTargetElement != NULL)
                  {
                      BSTR nn;
                      hr = pTargetElement-&gt;get_CurrentName(&amp;nn);
                      wprintf(L&quot;&gt;&gt; ELEMENT FOUND (%s)! &quot;, nn);
  
                  } else {
                      wprintf(L&quot;&gt;&gt; ELEMENT IS NULL&quot;);
                      goto cleanup;
                  }
              } else {
                  wprintf(L&quot;&gt;&gt; ELEMENT NOT FOUND! &quot;);
                  goto cleanup;
              }
          } else {
              wprintf(L&quot;&gt;&gt; SOMETHING WRONG WITH CONDITION &quot;);
              goto cleanup;
          }
      }
      else {
          wprintf(L&quot;&gt;&gt; NO WINDOW &quot;);
          goto cleanup;
      }
  cleanup:
      if (pTargetElement != NULL)
          pTargetElement-&gt;Release();
  
      if (pAutomation != NULL)
          pAutomation-&gt;Release();
  
      CoUninitialize();
      return ret;
  }
  </code></pre>
  <p>How should I approach this correctly and why after Accessibility Insights interaction my element can be found, is there some caching behind this?</p>