title: Using Ruby and watir-webdriver, how does one get the XPath of an element if the text is known?
body: <p>Using watir-webdriver, I am trying to click the "down" button next to some known text on the screen (in this case, <code>"An Example"</code>). When I click the down button, the text itself will move down a list of arbitrary length. I don't always know where the text will appear in the list, and also there is no ID on the text or the down button to uniquely identify the location to click. The button has a class attached (<code>"rowDown down"</code>), but as there can be multiple rows of text, the button class is not unique.</p>
  
  <p>In situations where I can't get get a unique ID, I always turn to XPath.</p>
  
  <p>In this case, I know the XPath of the text I care about will end with <code>/div[2]</code>
  and the button I want to click is in <code>div[1]</code>, more specifically the button I want will have XPath ending in <code>div[1]/button[2]</code></p>
  
  <p>The question is, how do I get the XPath for the text using watir-webdriver?
  (An example of the full XPath I could be dealing with is <code>"//*[@id='sortOrder0']/tbody/tr[2]/td[1]/div[2]"</code>.)
  Alternately, and equally acceptable, is there some other, reliable way of getting to the button I care about?</p>
  
  <p>Here is the relevant portion of my HTML, which produces an up arrow and a down arrow next to the words "An Example":</p>
  
  <pre><code>&lt;div&gt;
    &lt;button class="rowUp up"&gt;&lt;/button&gt;
    &lt;br /&gt;
    &lt;button class="rowDown down"&gt;&lt;/button&gt;
  &lt;/div&gt;
  &lt;div&gt;
    An Example
  &lt;/div&gt;
  </code></pre>