angular UI bootstrap datepicker不能使用JQuery表达式获取值

angular UI bootstrap datepicker can't get value using JQuery expression

本文关键字:JQuery 表达式 获取 UI bootstrap datepicker 不能 angular      更新时间:2023-09-26

我使用的是angular UI bootstrap lib中的datepicker。https://angular-ui.github.io/bootstrap//Datepicker

选择日期后,我无法使用JQuery表达式获得输入的文本。$ (" # effectiveDate ')。text ()总是返回空,但我可以看到它在页面上有值。

我能做什么来检索这个值?

更新:在chrome控制台

$ (' # effectiveDate ')返回:

[<input id=​"effectiveDate" name=​"effectiveDate" type=​"text" class=​"form-control pickdaterInput ng-valid ng-isolate-scope ng-valid-date ng-dirty ng-valid-parse ng-touched" datepicker-popup=​"dd-MMMM-yyyy" ng-model=​"elt.registrationState.effectiveDate" is-open=​"opened" min-date=​"minDate" datepicker-options=​"dateOptions" close-text=​"Close">​]

$ (' # effectiveDate ')。text ();回报;

""

angular.element(0)美元.scope .elt.registrationState()。effectiveDate回报:

Tue Jul 14 2015 00:00:00 GMT-0400 (Eastern Daylight Time)

但是在Selenium中:

        JavascriptExecutor js = (JavascriptExecutor) driver;
    String effectiveDate_string = js.executeScript("angular.element($0).scope().elt.registrationState.effectiveDate.getTime().toString()").toString();

给了错误:

org.openqa.selenium.WebDriverException: unknown error: $0 is not defined
(Session info: chrome=43.0.2357.132)
(Driver info: chromedriver=2.14.313457   (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86_64)   (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds

您是否尝试在Chrome (firefox)中单击实际输入元素,然后在控制台中键入此内容?

 angular.element($0).val()

还有,你试过这个了吗

 $('#effectiveDate').val()

而不是

$('#effectiveDate').text()

关于

注释

this is $('#effectiveDate')返回:[]

$('#effectiveDate')[0].val()

原因是当你调用$('# effecvedate ')时,你只得到一个你关心的值的数组,这意味着你必须得到数组的第一项,因此[0]。您也可以尝试这样做,以提高可读性。

$('#effectiveDate').first().val();