2016-07-26 12 views
0

日付ピッカーの要素を見つけることができません。私はCssSelectorとxpathとすべてを試みた。以下は私が試したコードです。日付ピッカーの要素を見つけることができません

コード:

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; 
      } 
     } 

ここではHTMLコードです。

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"/> 

ここでエラーです:

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

答えて

3

id値は動的に生成に見える、私の代わりにng-modelを使用します。

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

ボーナスとして読みやすさを向上させました。

さらに、wait until the presence of the elementが必要かどうかを確認してください。

+0

はい、動作していますが、指定した日付は選択されていません。特定の日付を選択する別の方法はありますか? –

+0

@sandeepkumarどのdatepickerを使っているのかわからないけど、td要素ではなく入力自体からテキスト値を読み込もうとしましたか? – Memfisto

+0

@ Memfistoええ、それは多くのthx働いた。 –

関連する問題