Html code:
<div class="leftpan-button leftpan-button-active" ui-sref="main.poList({status: 'Finalize'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Finalize">Finalize <!-- ngIf: vm.statusCount.PendingCount --><span class="badge pull-right ng-scope" style="background-color: rgb(255, 106, 0);" ng-if="vm.statusCount.PendingCount"></span><!-- end ngIf: vm.statusCount.PendingCount --></div>
Full div:
Status list :<div class="panel-body tagList"><div class="leftpan-button leftpan-button-active" ui-sref="main.poList({status: 'Finalize'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Finalize">Finalize <!-- ngIf: vm.statusCount.PendingCount --><span class="badge pull-right ng-scope" style="background-color: rgb(255, 106, 0);" ng-if="vm.statusCount.PendingCount"></span><!-- end ngIf: vm.statusCount.PendingCount --></div><div class="leftpan-button" ui-sref="main.poList({status: 'Pending for Approval'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Pending%20for%20Approval">Pending for approval <!-- ngIf: vm.statusCount.PendingCount --><span class="badge pull-right ng-binding ng-scope" style="background-color: rgb(255, 106, 0);" ng-if="vm.statusCount.PendingCount" ng-bind="vm.statusCount.PendingCount">11</span><!-- end ngIf: vm.statusCount.PendingCount --></div><div class="leftpan-button" ui-sref="main.poList({status: 'Draft'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Draft">Upcoming <!-- ngIf: vm.statusCount.UpcomingCount --><span class="badge pull-right ng-binding ng-scope" style="background-color: rgb(255, 106, 0);" data-ng-if="vm.statusCount.UpcomingCount" ng-bind="vm.statusCount.UpcomingCount">10</span><!-- end ngIf: vm.statusCount.UpcomingCount --></div><div class="leftpan-button" ui-sref="main.poList({status: 'Approved'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Approved">Approved <!-- ngIf: vm.statusCount.ApprovedCount --><span class="badge pull-right ng-binding ng-scope" style="background-color: rgb(255, 106, 0);" data-ng-if="vm.statusCount.ApprovedCount" ng-bind="vm.statusCount.ApprovedCount">38</span><!-- end ngIf: vm.statusCount.ApprovedCount --></div><div class="leftpan-button" ui-sref="main.poList({status: 'Rejected'})" ui-sref-active="leftpan-button-active" title="" href="#/main/po/Rejected">Rejected <!-- ngIf: vm.statusCount.RejectedCount --><span class="badge pull-right ng-binding ng-scope" style="background-color: rgb(255, 106, 0);" data-ng-if="vm.statusCount.RejectedCount" ng-bind="vm.statusCount.RejectedCount">9</span><!-- end ngIf: vm.statusCount.RejectedCount --></div></div>
I want to click on following Div, It is a link text.
I tried with a xpath,Css selector and link also, But I am getting following error: I tried xpath as :
driver.findElement(By.xpath("//*[@id='statusList']/div/div[1]").click();
CSS as:
driver.findElement(By.cssSelector("#statusList > div > div.leftpan-button.leftpan-button-active")).click();
Link as:
driver.findElement(By.linkText("Finalize")).click();
Wait even as:
WebDriverWait wait = new WebDriverWait(driver, 30);// 1 minute
wait.until(ExpectedConditions.visibilityOfElementLocated (By.cssSelector("#statusList > div > div.leftpan-button.leftpan-button-active")));
Result:
org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:261) at com.example.tests.FinalizePO.main(FinalizePO.java:41) Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#statusList > div
div.leftpan-button.leftpan-button-active"} (Session info: chrome=50.0.2661.102) (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40' System info: host: 'admin', ip: '192.168.51.205', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_60' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\BAYAPR~1\AppData\Local\Temp\scoped_dir1612_1332}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=50.0.2661.102, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 99a467e8f79b50f7c83ab694b88c2a75 *** Element info: {Using=css selector, value=#statusList > div > div.leftpan-button.leftpan-button-active} at sun.reflect.GeneratedConstructorAccessor8.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363) at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:492) at org.openqa.selenium.By$ByCssSelector.findElement(By.java:430) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355) at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:899) at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:897) at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205) at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:1) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:238) ... 1 more
statusList
present.. – Saurabh Gaurdriver.findElement(By.cssSelector("div[ng-if = "vm.statusCount.PendingCount"")).click();
. You might have to fix the quotations. – RemcoWcontains
with eitherui-sref
orui-sref-active
...? – ManishChristian