0

I have a Selenium script where I am trying to get the "list-item-value ng-binding" class from the Last Manual Run from the following:

  <div class="krn-modal-window">
<!-- ngIf: popupContentOptions.headerCancelButton.showButton --><button ng-disabled="popupContentOptions.headerCancelButton.action.disabled" class="jqx-window-close-button jqx-window-close-button-bluefin jqx-icon-close jqx-icon-close-bluefin ng-scope" ng-click="handleAction(popupContentOptions.headerCancelButton.action.clickHandlerName, popupContentOptions.headerCancelButton.action.actionName);" ng-if="popupContentOptions.headerCancelButton.showButton" autofocus=""></button>
<!-- end ngIf: popupContentOptions.headerCancelButton.showButton -->
<!-- ngIf: popupContentOptions.showHeader -->
<div class="modal-window__header ng-scope" ng-if="popupContentOptions.showHeader">
    <h4 ng-show="popupContentOptions.title.text" ng-bind="popupContentOptions.title.text | i18n" title="[undefined]" class="ng-binding ng-hide">[undefined]</h4>
    <h4 ng-show="popupContentOptions.title.localizedText" ng-bind="popupContentOptions.title.localizedText" title="Shift Builder" class="ng-binding">Shift Builder</h4>
</div>
<!-- end ngIf: popupContentOptions.showHeader -->
<div class="modal-window__body ng-scope">
    <ul class="list-group">
        <li><b ng-bind="::'html.eventManager.properties.jobId'| i18n" class="list-item-label ng-binding">Job ID</b>:
            <div ng-bind="::modal.properties.jobId" class="list-item-value ng-binding">209</div>
        </li>
        <li><b ng-bind="::'html.eventManager.properties.lastRun'| i18n" class="list-item-label ng-binding">Last run</b>:
            <div ng-bind="::modal.properties.lastRun" class="list-item-value ng-binding"></div>
        </li>
        <li><b ng-bind="::'html.eventManager.properties.nextRun'| i18n" class="list-item-label ng-binding">Next run</b>:
            <div ng-bind="::modal.properties.nextRun" class="list-item-value ng-binding">25/06/2023 1:27</div>
        </li>
        <li><b ng-bind="::'html.eventManager.properties.modifiedBy'| i18n" class="list-item-label ng-binding">Modified By</b>:
            <div ng-bind="::modal.properties.modifiedBy" class="list-item-value ng-binding">Updater for 209</div>
        </li>
        <li><b ng-bind="::'html.eventManager.properties.modifiedDate'| i18n" class="list-item-label ng-binding">Modified Date</b>:
            <div ng-bind="::modal.properties.modifiedDate" class="list-item-value ng-binding">15/03/2010 12:35</div>
        </li>
        <li><b ng-bind="::'html.eventManager.properties.lastManualRun'| i18n" class="list-item-label ng-binding">Last Manual Run</b>:
            <div ng-bind="::modal.properties.lastManualRun" class="list-item-value ng-binding">19/06/2023 11:45</div>
        </li>
        <li><b ng-bind="::'html.eventManager.properties.errorText'| i18n" class="list-item-label ng-binding">Error text</b>:
            <div ng-bind="::modal.properties.errorText" class="list-item-value ng-binding"></div>
        </li>
    </ul>
</div>

I've tried to use the list and loop through to list the values but it doesn't seem to like finding the elements within the

  • tags.

    Any ideas as I've not really got much experience dealing with these types of tables?

  • Anthony
    • 3
    • 2

    2 Answers2

    0

    Try the below XPath expression:

    //b[text()='Last Manual Run']//following::div[1]
    

    Example code:

    String text = driver.findElement(By.xpath("//b[text()='Last Manual Run']//following::div[1]")).getText();
    System.out.println(text);
    

    Output:

    19/06/2023 11:45
    
    Shawn
    • 4,064
    • 2
    • 11
    • 23
    0

    Given the HTML:

    <div class="modal-window__body ng-scope">
        <ul class="list-group">
        ...
        ...
        ...
        <li><b ng-bind="::'html.eventManager.properties.modifiedDate'| i18n" class="list-item-label ng-binding">Modified Date</b>:
            <div ng-bind="::modal.properties.modifiedDate" class="list-item-value ng-binding">15/03/2010 12:35</div>
        </li>
        <li><b ng-bind="::'html.eventManager.properties.lastManualRun'| i18n" class="list-item-label ng-binding">Last Manual Run</b>:
            <div ng-bind="::modal.properties.lastManualRun" class="list-item-value ng-binding">19/06/2023 11:45</div>
        </li>
        <li><b ng-bind="::'html.eventManager.properties.errorText'| i18n" class="list-item-label ng-binding">Error text</b>:
            <div ng-bind="::modal.properties.errorText" class="list-item-value ng-binding"></div>
        </li>
        </ul>
    </div>
    

    The desired <div> tag is the sibling of the <b> tag containing the text Last Manual Run and is an Angular element.


    Solution

    To extract the text 19/06/2023 11:45 ideally you need to induce WebDriverWait for the visibilityOfElementLocated() and you can use either of the following locator strategies:

    • Using xpath and following:

      System.out.println(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//b[contains(., 'Last Manual Run')]//following::div[1]"))).getText());
      
    • Using xpath and following-sibling:

      System.out.println(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//b[contains(., 'Last Manual Run')]//following-sibling::div[1]"))).getAttribute("innerHTML"));
      
    undetected Selenium
    • 183,867
    • 41
    • 278
    • 352