0

I am trying to identify items displayed in Advantage shopping page. I am using below properties to identify the objects. Object identification center identifying multiple objects but my script is returning 0

imgsCnt=browser.findChildren(WebElement.class,new WebElementDescription.Builder().className("ng-scope").tagName("LI").build());
System.out.println("# ItemsPresent : : "+imgsCnt.length);

WebPage URL : http://www.advantageonlineshopping.com:8080/#/category/5

I would like to identify the available items list using 'li' elements.

SQA_LEARN
  • 161
  • 1
  • 1
  • 8

1 Answers1

0

I managed to reproduce the problem.

The reason this happens is because the elements are really "not there" at the time the check (findChildren) is being made.

In order to get all the elements, some kind of wait needs to be added, to ensure the items are seen.

As such, the following code does work now, with the 5 seconds sleep. (Ofc another logic should be applied, this is just to demonstrate the solution).

public void test() throws Exception {
        Browser browser = BrowserFactory.launch(BrowserType.CHROME);
        browser.navigate("http://www.advantageonlineshopping.com:8080/#/category/Mice/5");
        Thread.sleep(5000); // this was the key difference between cnt 0 and cnt 11
        WebElement[] imgsCnt =  browser.findChildren(WebElement.class, new WebElementDescription.Builder()
                .className("ng-scope")
                .tagName("LI").build());
        System.out.println("# ItemsPresent : : "+imgsCnt.length);
        browser.close();
}
Adelin
  • 7,809
  • 5
  • 37
  • 65