2

The DOM I am working on has lots of nested elements (box inside box structure ) and I am finding it difficult to code using POM design pattern.

I have used FindsBy, FindsByAll, FindsBySequence but it appears that anytime I need to identify inner elements of a container, I will have to include finding the external element/container.

Is there a way to reuse the element 'DimensionPanel' instead of using [FindsBy(How = How.Id, Using = "container-dimpanel")]?

ex:

    [FindsBy(How = How.Id, Using = "container-dimpanel")]
    public IWebElement DimensionPanel { get; set; }

    #region DimensionPanel elements
    [FindsBySequence]
    [FindsBy(How = How.Id, Using = "container-dimpanel")]
    [FindsBy(How = How.Id, Using = "metrics-selector-container")]
    [FindsBy(How = How.TagName, Using = "a")]
    public IWebElement MetricsButton { get; set; }

    [FindsBySequence]
    [FindsBy(How = How.Id, Using = "container-dimpanel")]
    [FindsBy(How = How.Id, Using = "metrics-selector-container")]
    [FindsBy(How = How.TagName, Using = "span")]
    public IWebElement MetricsCount { get; set; }
    #endregion DimensionPanel elements
Meg-90
  • 259
  • 2
  • 8
  • Try single CSS or XPath selectors to get to the inner elements instead of multiple findbys. You can reuse the DimensionalPanel webelement to find inner elements using the findElement method of the webelement. There is no concept of setting an element to be the search context for another element in the FindBys annotation out of the box. Appium, mobile extension of selenium, has a concept of widgets which might help.Have not looked at in C# appium code but in Java there is a Widget class which can be used for non-mobile scenarios too.You can have a look at the C# implemetation and reuse it. – Grasshopper Nov 03 '16 at 17:40
  • Thank you for the answer, I am planning to use FindElement to look for inner elements. Reason I am hesitant to use CSS or XPath is because, DOM consists of same elements in different containers and by using those locators, I will need to provide a path which will be much longer and difficult to debug if element changes. – Meg-90 Nov 03 '16 at 18:44

1 Answers1

0

I'm not sure if this helpful for you but in java you can use the FindBy annotation like this

@FindBy (id="metrics-selector-container")
public WebElement DimensionPanel;
mohamed faisal
  • 177
  • 2
  • 12