Friday, 15 May 2015

c# - How to find a WebElement by another WebElement using Page Factory -


A brief scan was made on the source code, it is not certain what is the best practice for it.

For example, I have a page object 'dummyPage', which has two panel elements TopPanel and BottomPanel . Each panel contains some elements, which are found by driver.FindElement () instead of TopPanel.FindElement () . How to apply page factory for this?

I know that takes in PageFactory.InitElements (ISearchContext, Object) ISearchContext , however, I do not believe that I have the page and How can I use elements of a section of the panel.

  public class dumppage {private identifier driver; Public Dmepage (IWebDriver Driver) {this.driver = driver; } Public ILIST & lt; IWebElement & gt; Dummy Links {Return Driver. Fix Elements (By C. CSSEcler ("Some Dummy-Link"); }} Public IWebElement TopPanel {Return Driver. Fix Element ("top-panel"); }} Panan {get {return driver.FindElement (By.Id ("bottom-panel") below public IWebElement;) }} Public IWebElement FooInTopPanel {Get TopPanel.FindElement (By.CssSelector (". Something")); }} Public IWebElement FooInBottomPanel {Get BottomPanel.FindElement (By.CssSelector (". Something")); }}} Public class DummyPageWithPageFactory {Public DummyPageWithPageFactory (IWebDriver Driver) {PageFactory.InitElements (driver, this); } [Finds (how = how. Csseterator, experiment = "some dummy-link")] Public ILIT & lt; IWebElement & gt; Dummy Links {Receive; Private set; } [Searches (how = how. Id, experiment = "top-panel")] Public IWebElement TopPanel {get; Private set; } [Finds (how = how. Id, experiment = "bottom-panel")] Public below IWebElement {get; Private set; } // Public IWebElement FooInTopPanel {get; Private set; } // Public IWebElement FooInBottomPanel {Receive; Private set; }}   

If I use driver.FindElement () for all the codes and connect all the locators, then I face another situation You may have to, so that all the locksmiths are too long and I can not use the variable inside the C # features. [Finds (how = how to use .csslactor, use = "#top-panel .blah .blah .super-long-blah."]] [Finds (how to = Csseterter, experiment = "top-panel blah blah super-long-blah new-new") [Finds how (= how to use ccSilator = "#down-panel.blah. Blah .super-long-blah. "]]

See this:

  [Finds (how = how to name, experiment = "anElementName", priority = 0)] [Finds (how = a The. Name, use = "differentElementName", Priority = 1)] public IWebElement this Element;    

No comments:

Post a Comment