brij
brij

Reputation: 217

Selenium - Not able to Click Dynamically Visible Menu

I have a Menu which have li (list) elements which gets enabled after you mouse-hover a particular label.

    driver.get("www.snapdeal.com");   Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("loggedOutAccount"))).build().perform();
    //Wait for 5 Secs
   driver.findElement(By.className("accountLink")).click();// Here it's throwing Element not visible exception

This code is doing the mouse-hover properly but not able to click the "SignIn Link" Link. Though on manually checking the element is Visible

DOM Structure -

<div id="loggedOutAccount" class="hd-rvmp-logout">
<a class="signIn" href="javascript:void(0);">
<i class="iconHeader accountUser"></i>
<label class="my-account-lang"> My Account</label>
<i class="mar_2_left right-downArrow breadcrumbArrow-down"></i>
</a>
<div class="sdNavDropWrapper accDetails" style="display: none; z-index: 999;">
<ul class="positionAbsolute pull-right">
<li class="customLoggedInState">
<div class="left triangle"></div>
<div class="right triangle"></div>
<div>
<a class="accountLink" href="javascript:void(0);">Click here to sign in ></a>
</div>
</li>
<li class="stop-event">
<li class="stop-event">
<li class="stop-event">
<li class="stop-event">
<li class="stop-event">
</ul>
</div>
</div>

Upvotes: 0

Views: 1225

Answers (1)

Helping Hands
Helping Hands

Reputation: 5396

Please use xpath for both element like below :

driver.get("www.snapdeal.com");   
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath("yourxpathhere"))).build().perform();

driver.findElement(By.xpath("yourxpathhere")).click();

I think class/Id repeating for other elements also for style purpose. so Xpath is better to find unique element.

Upvotes: 1

Related Questions