2014-11-04 59 views
0

我在分頁表的頁腳中有一個文本框。此文本框包含一個帶有向上和向下箭頭的文本框,如下圖所示。當我們點擊下一個,上一個按鈕時,這個文本框的值會動態地改變。從文本框中的上下箭頭在Selenium Webdriver中獲取文本

圖像URL:http://i.msdn.microsoft.com/dynimg/IC1380.jpg

這是從DOM輸入

<div ng-grid-footer="" class="ng-scope"><div ng-show="showFooter" class="ngFooterPanel ng-scope ui-widget-content ui-corner-bottom" ng-class="{'ui-widget-content': jqueryUITheme, 'ui-corner-bottom': jqueryUITheme}" ng-style="footerStyle()" style="width: 1920px; height: 55px;"> 
<div class="ngTotalSelectContainer"> 
    <div class="ngFooterTotalItems ngNoMultiSelect" ng-class="{'ngNoMultiSelect': !multiSelect}" style="margin-top: 8px"> 
     <span class="ngLabel ng-binding">Total Items: 810</span><span ng-show="filterText.length > 0" class="ngLabel ng-binding ng-hide">(Showing Items: 100)</span> 
    </div> 
    <div class="ngFooterSelectedItems ng-hide" ng-show="multiSelect"> 
     <span class="ngLabel ng-binding">Selected Items: 0</span> 
    </div> 
</div> 
<div class="ngPagerContainer ngNoMultiSelect" style="float: right; margin-top: 10px" ng-show="enablePaging" ng-class="{'ngNoMultiSelect': !multiSelect}"> 
    <div style="float:left; margin-right: 10px" class="ngRowCountPicker"> 
     <span style="float: left; margin-top: 8px" class="ngLabel ng-binding">Page Size:</span> 
     <select style="float: left;height: 29px; width: 100px" ng-model="pagingOptions.pageSize" class="ng-valid ng-dirty"> 
      <!-- ngRepeat: size in pagingOptions.pageSizes --><option ng-repeat="size in pagingOptions.pageSizes" class="ng-scope ng-binding" value="10">10</option><!-- end ngRepeat: size in pagingOptions.pageSizes --><option ng-repeat="size in pagingOptions.pageSizes" class="ng-scope ng-binding" value="25">25</option><!-- end ngRepeat: size in pagingOptions.pageSizes --><option ng-repeat="size in pagingOptions.pageSizes" class="ng-scope ng-binding" value="50">50</option><!-- end ngRepeat: size in pagingOptions.pageSizes --><option ng-repeat="size in pagingOptions.pageSizes" class="ng-scope ng-binding" value="100">100</option><!-- end ngRepeat: size in pagingOptions.pageSizes --> 
     </select> 
    </div> 
    <div style="float:left; margin-right: 10px; line-height:25px" class="ngPagerControl"> 
     <button class="ngPagerButton" ng-click="pageToFirst()" ng-disabled="cantPageBackward()" title="First Page"><div class="ngPagerFirstTriangle"><div class="ngPagerFirstBar"></div></div></button> 
     <button class="ngPagerButton" ng-click="pageBackward()" ng-disabled="cantPageBackward()" title="Previous Page"><div class="ngPagerFirstTriangle ngPagerPrevTriangle"></div></button> 

     <!--Input Textbox Which I want to Inspect --> 
     <input class="ngPagerCurrent ng-valid-number ng-valid-min ng-valid ng-valid-max ng-dirty" min="1" max="9" type="number" style="width:50px; height: 26px; margin-top: 1px; padding: 0 4px" ng-model="pagingOptions.currentPage"> 
     <!--END--> 

     <button class="ngPagerButton" ng-click="pageForward()" ng-disabled="cantPageForward()" title="Next Page"><div class="ngPagerLastTriangle ngPagerNextTriangle"></div></button> 
     <button class="ngPagerButton" ng-click="pageToLast()" ng-disabled="cantPageToLast()" title="Last Page"><div class="ngPagerLastTriangle"><div class="ngPagerLastBar"></div></div></button> 

     <button ng-controller="OmniSearchViewCtrl" id="page-summary-help-button" title="Help" class="ngPagerButton ng-scope" ng-click="handlePageSummaryHelpButtonClick()"> 
      <span class="ptipsicon ptipsicon-help" style="padding:0 6px; float:left"></span> 
     </button> 

    </div> 
</div> 

這是Xpath的

//*[@id="PageViewContainer"]/div/div[3]/div/div[2]/div[2]/input 

我的p問題是,我無法從文本框中獲取值,因爲文本框沒有任何屬性:值。我已經嘗試使用下面的幾行來獲取文本,但它只是顯示一個空白。然而,我沒有得到任何例外

pageNumber = findElement(By.xpath(properties.getString("PageNumber"))).getText(); 
pageNumber = findElement(By.xpath(properties.getString("PageNumber"))).getAttribute("value"); 

而,當我試着這個,我沒有得到這樣的元素髮現異常。

pageNumber = findElement(By.xpath("//input[@id=\"PageViewContainer\"]"))).getText(); 

任何幫助將不勝感激。

+0

什麼是properties.getString(「PageNumber」)返回? – CharlieS 2014-11-04 00:20:30

+0

我只是從屬性文件中獲取xpath。假設那裏沒有問題。謝謝 – vkrams 2014-11-04 00:21:27

+0

當文本出現時,您需要檢查元素,並向我們顯示包含您希望提取的文本的HTML。您提供的xpath與您顯示的HTML代碼段無關。沒有顯示ID爲「PageViewContainer」的元素。 – CharlieS 2014-11-04 00:24:33

回答

1
//*[@id="PageViewContainer"] 

您的xpath以搜索id爲「PageViewContainer」的元素開頭。 HTML中沒有這樣的元素,所以你的xpath不會返回任何內容。

根據你給的代碼片段,您可以找到輸入元素:

//div[@class='ngPagerControl']/input 

然後,您可以使用的getText()方法來提取文本值。

+0

明白了謝謝:-) – vkrams 2014-11-05 23:14:37

相關問題