Selenium Webdriver: Page factory initialization using paths relative to other elements?

前端 未结 2 1577
逝去的感伤
逝去的感伤 2021-01-03 00:53

I\'m trying to write a page object in Selenium Webdriver using the page factory @FindBy annotations. The page object is for a sidebar, and the parent WebElement

2条回答
  •  囚心锁ツ
    2021-01-03 01:11

    No, it is not possible this way. But you can use getter methods instead of annotation-based initialization:

    public class SomePage {
        @FindBy (xpath = "//div[contains(@class,'yui3-accordion-panel-content') and   child::div[.='Sidebar']]")
        private WebElement sidebar;
    
        private WebElement getSomeChildElement() {
            return siderbar.findElement(By.id("somechild"));
        }
    }
    

提交回复
热议问题