title: I am using Selenium-webdriver and I need to select an element by its "text"
body: <p>I need dynamic <code>xpath</code> because the one I have is not finding an element.</p>
  <pre><code> public void selectCheckBox(WebElement wrapper, String value) {
      scrollTo(wrapper);
      String xpath = &quot;.//label[span/text()='&quot; + value + &quot;']//input[@type='checkbox']&quot;;
      try {
          WebElement checkboxButton = wrapper.findElement(By.xpath(xpath));
          checkboxButton.click();
          waitPageBusy();
      } catch (NoSuchElementException e) {
          // Checkbox not found.
          step(&quot;Missing checkbox: &quot; + value, () -&gt; {
              attachment(&quot;Available values&quot;, String.join(&quot;\n&quot;, getRadioValues(wrapper)));
              throw new NoSuchElementException(&quot;Missing checkbox: &quot; + value, e);
          });
      }
  }
  </code></pre>