0

I am trying to click a menu item from a navigation bar. I was able to click the first menu item and navigate to that page. But when I tried to navigate to other pages it always gives ElementNotVisibleException.

HTML for the menu items.

<ul id="yw1" class="dropdown-menu">
 <li id="people_add"><a tabindex="-1" href="/index.php/People/add"><i class="fa fa-plus fa-1x "></i> Add People</a></li>
 <li id="people_search"><a tabindex="-1" href="/index.php/people/search"><i class="fa fa-search fa-1x "></i> Search People</a></li>
 <li id="people_merge"><a tabindex="-1" href="/index.php/people/mergeDup"><i class="fa fa-user fa-1x "></i> Merge Duplicates</a></li>
 <li id="bulk_insert"><a tabindex="-1" href="/index.php/BulkInsert/Admin"><i class="fa fa-file fa-1x "></i> Bulk Insert</a></li>
 </ul>

This code works for the first menu item.

driver1.findElement(By.id("people_add")).click();

But It doesn't work for the second menu item or any other.

driver1.findElement(By.id("people_search")).click();

I tried the xpath for the second menu item. but it also didn't work.I still got element not visible exception again.

How can I fix this?

Darshani Kaushalya
  • 115
  • 1
  • 2
  • 12
  • What exactly do you mean by `doesn't work`? Do you see any error? Update the question with the error stack trace. – undetected Selenium Jan 11 '18 at 11:28
  • is menu item visible always or will be visible only when mouse over on main menu? – Murthi Jan 11 '18 at 12:09
  • Possible duplicate of [ElementNotVisibleException : Selenium Python](https://stackoverflow.com/questions/47108512/elementnotvisibleexception-selenium-python) – undetected Selenium Jan 11 '18 at 12:58
  • I guess there more than one element which id is 'people_search' and the first one is not visible. please confirm this by DevTool manaully to see css selector: #people_search can match how many elements on the problem page. – yong Jan 11 '18 at 14:39
  • @yong I have only one people_search. – Darshani Kaushalya Jan 12 '18 at 05:42
  • The problem was, I was trying to click the people_search without clicking the Main menu item "People". There for Selenium couldn't find the people_search element. Thank you for your feedback. It helped me to understand the mistake I have done. – Darshani Kaushalya Jan 12 '18 at 06:12

1 Answers1

0

If you have mutiple frames in your application then try to go to the default content before clicking the second menu item.

driver.switchTo().defaultContent();

driver1.findElement(By.id("people_search")).click();

Community
  • 1
  • 1
subin
  • 71
  • 7