0

I am unable to locate an element of date picker. I tried CssSelector and xpath and everything. Below is the code i tried.

Code :

WebElement dateWidget = driver.findElement(By.xpath(".//*[@id='dp1469511990123']"));
        List<WebElement> columns=dateWidget.findElements(By.tagName("td"));

        for (WebElement cell: columns)
        {
             if (cell.getText().equals("21"))
             {
              cell.findElement(By.linkText("21")).click();
              break;
             }
        }

Here is HTML code.

HTML :

<input id="dp1469511990123" class="ng-pristine ng-untouched ng-valid hasDatepicker ng-not-empty" type="text" ng-disabled="input.p1Edit==0" ng-model="vendor.companyStartedDate" ui-date="comp_st_date" disabled="disabled"/>

Here is the Error:

org.openqa.selenium.NoSuchElementException: Unable to locate element: >{"method":"xpath","selector":".//*[@id='dp1469511990123']"} Command duration or timeout: 10.07 seconds For documentation on this error, please visit: >http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.53.0', revision: >'35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46' System info: host: 'user-PC', ip: '192.168.1.52', os.name: 'Windows 7', >os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_51' Driver info: org.openqa.selenium.firefox.FirefoxDriver

sandeep kumar
  • 195
  • 1
  • 4
  • 20

1 Answers1

3

The id value looks dynamically generated, I would use an ng-model instead:

driver.findElement(By.cssSelector("[ng-model='vendor.companyStartedDate']"));

Count improved readability as a bonus.

And, see if you need to wait until the presence of the element.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Yes it is working but it is not selecting date what i have given. Is there any alternate way to select particular date. – sandeep kumar Jul 26 '16 at 06:18
  • @sandeepkumar not sure which datepicker you're using, but have you tried to read the text value from the input itself rather than from td elements? – Memfisto Jul 26 '16 at 06:21
  • @sandeepkumar You can check this for [selecting date from datepicker](http://stackoverflow.com/a/38402746/3122133) – Madhan Jul 26 '16 at 06:42