0

I Want to click on navigation bar using selenium web driver

My Html code is

<div class="navbar-inner">
            <div class="container">
            <a class="navbar-brand " ui-sref="home" href="#/"><i class="glyphicon glyphicon-home"></i> iWatch Project</a>
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="navbar-collapse collapse ng-scope" id="bs-navbar-collapse-1" data-ng-controller="uiUserNavigationController">
                <ul class=" nav navbar-nav">
                    <li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="contractList" href="#/contract"><i class="glyphicon glyphicon-plus"></i> Contract Information</a></li>
                    <li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="civilList" href="#/civil"><i class="glyphicon glyphicon-plus"></i> Civil </a></li>
                    <li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="emList" href="#/em"><i class="glyphicon glyphicon-plus"></i> E&amp;M </a></li>
                    <li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="safetyList" href="#/safety"><i class="glyphicon glyphicon-plus"></i> Safety </a></li>
                    <li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="workOrderList" href="#/workOrder"><i class="glyphicon glyphicon-plus"></i> Utility Diversion </a></li>
                    <li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="iPadView" href="#/iPadView"><i class="glyphicon glyphicon-plus"></i> iPad View</a></li>
                    <li class="dropdown ng-hide" data-ng-hide="!userInfo.isAuthenticated">
                        <a class="btn dropdown-toggle ng-binding" href="#" aria-haspopup="true" aria-expanded="false">
                            Hi, <i class="glyphicon glyphicon-user"></i>  !
                        </a>
                        <ul class="dropdown-menu">
                            <li data-ng-hide="!userInfo.isAuthenticated" class="ng-hide"><a ui-sref="user.intray" href="#/user/intray"><i class="glyphicon glyphicon-tasks"></i> My Tasks</a></li>
                            <li data-ng-hide="!userInfo.isAuthenticated || !isPlanner" class="ng-hide"><a ui-sref="requestAccess.CV" href="#/requestAccess/CV"><i class="glyphicon glyphicon-eye-open"></i> Request Access</a></li>
                            <li data-ng-hide="!userInfo.isAuthenticated" class="ng-hide"><a ui-sref="userChangePassword" href="#/changepassword"><i class="glyphicon glyphicon-lock"></i> Change Password</a></li>
                            <!--<li data-ng-hide="!userInfo.isAuthenticated"><a ui-sref="userSettings"><i class="glyphicon glyphicon-edit"></i> User Settings</a></li>-->
                            <li data-ng-hide="!userInfo.isAuthenticated" class="ng-hide"><a ui-sref="userClaims" href="#/userClaims"><i class="glyphicon glyphicon-wrench"></i> User Claims</a></li>
                            <li data-ng-hide="!userInfo.isAuthenticated" class="ng-hide"><a href="" data-ng-click="logOut()"><i class="glyphicon glyphicon-log-out"></i> Logout</a></li>
                        </ul>
                    </li>
                    <li data-ng-hide="userInfo.isAuthenticated" class=""><a href="" data-ng-click="LogIn()"><i class="glyphicon glyphicon-log-in"></i> Login</a></li>
                </ul>
            </div>
        </div>
        </div>

I want to click on the marked part from selenium.

**<a href="" data-ng-click="LogIn()">**

What I tried

driverIE.findElement(By.cssSelector("a[href*=LogIn()]")).click();

Any help on this - would help

2 Answers 2

2

click by using link text if dont have xpath

driverIE.findElement(By.linkText("Login")).click()

You can also do the same by using partial match if you are not sure about the exact link text

driver.findElement(By.partialLinkText("Log")).click();
Sign up to request clarification or add additional context in comments.

Comments

1

You could also get this element by using xpath:

 driverIE.findElement(By.xpath("//a[@data-ng-click='LogIn()']")).click();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.