title: Finding your main window element in Winium.Cruciatus
body: <p>I don't suppose many are using <a href="https://github.com/2gis/Winium.Cruciatus" rel="nofollow">Winium.Cruciatus</a> or the <a href="https://github.com/2gis/Winium.Desktop" rel="nofollow">Winium.Desktop WebDriver</a> implementation but if anyone is maybe you can help or benefit from my workaround.</p>
  
  <p>I use the <a href="https://github.com/2gis/Winium.Desktop" rel="nofollow">WebDriver</a> implementation to start my application, something like this:</p>
  
  <pre><code>capabilities = { 'app' =&gt; path, 'launchDelay' =&gt; 1500 }
  driver = Selenium::WebDriver.for(:remote,
                                     url: 'http://127.0.0.1:9999',
                                     desired_capabilities: capabilities)
  </code></pre>
  
  <p>The application starts just fine <em>but</em> I need to find the root element to be able to find children without scouring the entire automation tree every time.</p>
  
  <p>I used to do this:</p>
  
  <pre><code>wait.until { @driver.find_element(:id, 'appid') }
  </code></pre>
  
  <p>Which works fine if the application is loaded and if there's not too many windows open. However, when I've got like 10-15 windows open and the application takes a few seconds to start the cruciatus library just hangs. I've tracked this down to the automation library itself, it hangs. I think this is due to the application not having been loaded when the library peruses the element tree and it starts going through each and every element in the scope which takes ages and probably ends in a stack overflow in the end (<a href="https://msdn.microsoft.com/en-us/library/system.windows.automation.automationelement.findfirst(v=vs.110).aspx?f=255&amp;MSPPError=-2147217396#Anchor_1" rel="nofollow">according to MSDN</a>).</p>
  
  <p>I've even tried fixing the Cruciatus implementation myself but since this is an inherent issue in the slowness of enumerating elements it didn't really help even if I put in a timeout in Cruciatus. </p>
  
  <p>I'll provide my workaround as an answer but if anyone has a better suggestion it would be much appreciated?</p>