如何从WebDriver获取当前WebElement上的CSS选择器字符串

时间:2015-08-04 21:37:06

标签: jquery css selenium webdriver

我想在当前的WebElement上重用CSS选择器。有没有办法解决它?原因是我想在条件满足时重新选择元素,以便我想添加"> *"在By.cssSelector()中获取子DOM元素。到目前为止,我只能执行tagName(),但没有保证选择正确的。

List<WebElement> webElements = DMDriver.findElements(By.cssSelector(cssSelectorNode));
  WebElement selectedRootFolder = null;

  if (webElements.size() > 0)
  {
    for (WebElement webElement : webElements)
    {
      if (webElement.getText().trim().equals(strFolder))
      {
        webElement.findElement(By.tagName("..."));

...

HTML代码(由Angular JS生成)

<div class="folder-rows-wrapper" ng-nice-scroll="" style="overflow: hidden;" tabindex="1">
<div class="folder-rows my-docs ya-treeview ng-isolate-scope" ya-context="context" ya-options="options" ya-model="tree" ya-id="myDocsTree" ya-treeview="">
<div class="ya-node" ya-node="">
    <ul class="list-unstyled ng-scope" ng-hide="node.collapsed">
        <li class="node ng-scope" ng-repeat="node in node.$children">
            <div class="" ng-show="node.$hasChildren">
                <a class="btn btn-link pull-left" ng-click="expand($event, node)" ng-show="node.collapsed">
                    <i class="glyphicon glyphicon-chevron-right"></i>
                </a>
                <a class="btn btn-link pull-left ng-hide" ng-click="collapse($event, node)" ng-hide="node.collapsed">
                    <i class="glyphicon glyphicon-chevron-down"></i>
                </a>
            </div>
            <div class="node-content clearfix" ng-dblclick="dblClick($event, node)" ng-click="selectNode($event, node)" ya-transclude="">
                <span class="row-folder ng-scope" ng-class="{open: node.collapsed == false}" context-menu-item="node.$model" context-menu-method="actionsMenuOptions" context-menu="">
                    <span class="folder-name name ng-binding">SharedFolderAgainAgain</span>
                </span>
            </div>
            <div class="ya-node" ya-node="">
                <ul class="list-unstyled ng-scope ng-hide" ng-hide="node.collapsed"></ul>
            </div>
        </li>
<li class="node ng-scope" ng-repeat="node in node.$children">
...
<li class="node ng-scope" ng-repeat="node in node.$children">
...

粘贴框链接可供您轻松阅读 - http://pastebin.com/WtbCPZ2L

0 个答案:

没有答案