Help with Xpath

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
526
Благодарностей
112
Баллы
43
I'm trying to use Xpath to do some tasks.
This is my first time who I'm trying to use a variable mixed with Xpath code, my problem is... if I put a number direct in the Xpath code, the code returns "error" if I put the same number from a variable the code returns sucess...

If I run that code on this DOM:
Код:
<div class="ng-isolate-scope" vr-pagination="" page="transacoesPage" page-quantity="transacoesPageQuantity" page-limit="pageLimit" page-change-request="changeTransacoesPage">

  <!-- paginacao v1 -->
  <nav class="text-center no-print u-legacy--hide-v2">
  <ul class="pagination">
  <li class="ng-hide" ng-show="showLeftPaginationArrow()">
  <a href="javascript:void(0)" ng-click="changePage(pagination[0].page - 1)">
  <span aria-hidden="true">
  <i class="fa fa-angle-left"></i>
  </span>
  </a>
  </li>
  <!-- ngRepeat: item in pagination | limitTo:pageLimit --><li class="ng-scope" ng-repeat="item in pagination | limitTo:pageLimit">
  <a class="ng-binding active" href="javascript:void(0)" ng-click="changePage(item.page)" ng-class="{'active':item.page === page}">1</a>
  </li><!-- end ngRepeat: item in pagination | limitTo:pageLimit --><li class="ng-scope" ng-repeat="item in pagination | limitTo:pageLimit">
  <a class="ng-binding" href="javascript:void(0)" ng-click="changePage(item.page)" ng-class="{'active':item.page === page}">2</a>
  </li><!-- end ngRepeat: item in pagination | limitTo:pageLimit -->
  <li class="ng-hide" ng-show="showRightPaginationArrow()">
  <a href="javascript:void(0)" ng-click="changePage(pagination[pageLimit].page)">
  <span aria-hidden="true">
  <i class="fa fa-angle-right"></i>
  </span>
  </a>
  </li>
  </ul>
  </nav>
  <!-- end paginacao v1 -->

  <!-- paginacao v2 -->
  <nav class="c-pagination u-legacy--hide-v1">
  <ul class="o-list-inline c-pagination">
  <li class="o-list-inline__item c-pagination__item ng-hide" ng-show="showLeftPaginationArrow()">
  <a href="javascript:void(0)" class="c-btn c-btn--icon c-btn--small" ng-click="changePage(pagination[0].page - 1)">
  <svg class="c-btn__icon c-btn__icon--default">
  <use xlink:href="#micro-arrow-left"></use>
  </svg>
  </a>
  </li>
  <!-- ngRepeat: item in pagination | limitTo:pageLimit --><li class="o-list-inline__item c-pagination__item ng-scope" ng-repeat="item in pagination | limitTo:pageLimit">
  <a class="ng-binding is-active" href="javascript:void(0)" ng-click="changePage(item.page)" ng-class="{'is-active':item.page === page}">1</a>
  </li><!-- end ngRepeat: item in pagination | limitTo:pageLimit --><li class="o-list-inline__item c-pagination__item ng-scope" ng-repeat="item in pagination | limitTo:pageLimit">
  <a class="ng-binding" href="javascript:void(0)" ng-click="changePage(item.page)" ng-class="{'is-active':item.page === page}">2</a>
  </li><!-- end ngRepeat: item in pagination | limitTo:pageLimit -->
  <li class="o-list-inline__item c-pagination__item ng-hide" ng-show="showRightPaginationArrow()">
  <a href="javascript:void(0)" class="c-btn c-btn--icon c-btn--small" ng-click="changePage(pagination[pageLimit].page)">
  <svg class="c-btn__icon c-btn__icon--default">
  <use xlink:href="#micro-arrow-right"></use>
  </svg>
  </a>
  </li>
  </ul>
  </nav>
  <!-- end paginacao v2 -->
</div>
Example code who will return error (I want to get error!)
Код:
string xpath = "(//div[@page='transacoesPage']/nav/ul/li/a[@class='ng-binding'][contains(.,'3'])";
string dothis= "rise|click";
string set ="";

return CommonCode.FindElementAndExecuteAction(instance, xpath, dothis, set);

Now, if I have a variable "counter" and it value is "3", the result is success:
Код:
string str = project.Variables["counter"].Value;
string xpath = "(//div[@page='transacoesPage']/nav/ul/li/a[@class='ng-binding'][contains(.,str])";
string dothis= "rise|click";
string set ="";
instance.Variables["test"].Value = project.Variables["counter"].Value;
return CommonCode.FindElementAndExecuteAction(instance, xpath, dothis, set);
There is a way to use a variable from zenno to use it on Xpath?
the value of variable "test" return 3...
 

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
526
Благодарностей
112
Баллы
43
Found error by my self.... fail in C#...
...[contains(.,"+str+")";
Done.
 
Последнее редактирование:
  • Спасибо
Реакции: LightWood

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)