How to traverse DOM (children/siblings) using watir-webdriver?
<p>I'm used to using PHP's <a href="http://simplehtmldom.sourceforge.net/manual.htm" rel="nofollow">Simple HTML DOM Parser</a>(SHDP) to access elements, but I'm using ruby now with watir-webdriver, and I'm wondering if this can replace the functionality of SHDP as far as accessing elements on pages goes.</p>

<p>So in SHDP I'd do this:</p>

<pre><code>$ret = $html-&gt;find('div[id=foo]');
</code></pre>

<p>Which is an array of all instances of <code>div</code>s with <code>id=foo</code>. Oh, and <code>$html</code> is the HTML source of a specified URL. Anyway, so then I'd put it in a loop:</p>

<pre><code>foreach($ret as $element) 
       echo $element-&gt;first_child ()-&gt;first_child ()-&gt;first_child ()-&gt;first_child ()-&gt;first_child ()-&gt;first_child ()-&gt;first_child ()-&gt;plaintext . '&lt;br&gt;';
</code></pre>

<p>Now, here, each <code>-&gt;first_child()</code> is a child of the parent <code>div</code> with <code>id=foo</code> (notice I have seven) and then I print the plaintext of the 7th child. Something like this</p>

<pre><code>&lt;div id="foo"&gt;
    &lt;div ...&gt;
        &lt;div ...&gt;
            &lt;div ...&gt;
                &lt;div ...&gt;
                    &lt;div ...&gt;
                        &lt;div ...&gt;
                            &lt;div ...&gt;HAPPINESS&lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div
&lt;/div&gt;
</code></pre>

<p>would get "HAPPINESS" printed. So, my question is, how can this be done using watir-webdriver (if it all possible)?</p>

<p>Also, and more generally, how can I get SHDP's DOM-traversing abilities in watir-webdriver:</p>

<p><a href="http://i.stack.imgur.com/0EnQp.png" rel="nofollow">enter image description here</a></p>

<p>I ask because if watir-webdriver can't do this, I'm going to have to figure out a way to pipe source of a browser instance in watir-webdriver to a PHP script that uses SHDP and get it that way, and somehow get it back to ruby with the relevant information...</p>