driver.get("https://www.yahoo.com/");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
List<WebElement> optionCount = driver.findElements(By.xpath("//*[@id=\"mega-bottombar\"]"));
System.out.println(optionCount.size());
Asked
Active
Viewed 75 times
1

undetected Selenium
- 183,867
- 41
- 278
- 352

Kamran Xeb
- 49
- 1
- 8
2 Answers
0
This will return a list of the menu items:
List<WebElement> list = driver.findElements(By.xpath("//*[@id="mega-bottombar"]//li"));
So... list.size()
returns 8, which according to your comment is what you're after.

Bill Hileman
- 2,798
- 2
- 17
- 24
-
driver.get("https://www.yahoo.com/"); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); List
optionCount = driver.findElements(By.xpath("//*[@id=\"mega-bottombar\"]")); System.out.println(optionCount.size()); trying this still not getting all the elements – Kamran Xeb Apr 30 '18 at 20:48
0
As you are trying to get the count of items in yahoo top panel just after invoking get()
method you have to induce WebDriverWait and you can use the following code block :
driver.get("https://www.yahoo.com/");
List<WebElement> optionCount = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@id='mega-bottombar']/ul//li/a")));
System.out.println(optionCount.size());
Console Output :
9
Note : The link with text as Cricket seems to be missing from your snapshot you have provided.

undetected Selenium
- 183,867
- 41
- 278
- 352
-
-
@Rajagopalan _explicitwait_ is much more optimized with respect to _implicit wait_ – undetected Selenium May 01 '18 at 06:28
-
@Rajagopalan Check the discussions [What is the internal working difference between Implicit Wait and Explicit Wait](https://stackoverflow.com/questions/46365040/what-is-the-internal-working-difference-between-implicit-wait-and-explicit-wait/46398760#46398760), [Implicit vs Explicit vs Fluent Wait](https://stackoverflow.com/questions/48145111/implicit-vs-explicit-vs-fluent-wait/48162909#48162909), [Differences between impilicit, explicit and fluentwait](https://stackoverflow.com/questions/28658418/differences-between-impilicit-explicit-and-fluentwait/48323031#48323031) – undetected Selenium May 01 '18 at 07:13