title: Selenium Webdriver: Page factory initialization using paths relative to other elements?
body: <p>I'm trying to write a page object in Selenium Webdriver using the page factory <code>@FindBy</code> annotations. The page object is for a sidebar, and the parent WebElement containing all elements the page object needs to interact with is initialized in this way:</p>
  
  <pre><code>@FindBy (xpath = "//div[contains(@class,'yui3-accordion-panel-content') and child::div[.='Sidebar']]")
  WebElement sidebar;
  </code></pre>
  
  <p>I then want the search input relative to this <code>sidebar</code> element. Is there a way to do this referencing <code>sidebar</code> element? I could copy and paste the entire path to the beginning:</p>
  
  <pre><code>@FindBy (xpath = "//div[contains(@class,'yui3-accordion-panel-content') and child::div[.='Sidebar']]//input[@id='search']")
  </code></pre>
  
  <p>But I'd much rather make it relative to the first element. Is anything like this possible?</p>
  
  <pre><code>@FindBy (parent = "sidebar", xpath = ".//input[@id='search']")
  </code></pre>
  
  <p>The <a href="http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/FindBy.html" rel="noreferrer">Selenium documentation on the @FindBy annotation</a> is a bit lacking...</p>