How to count the number of links whose values do not contain "Input Process case"

Issue

The web page I work with contains links with the value "Input Process case", and without the value "Input Process case". How do I count the number of links that do not contain the "Input Process case" value

enter image description here

This is code snippet of links with "Input Process case" value

<tr valign="top">
<td valign="middle" class="text ibr">
&nbsp;
<a tabindex="0" title="Input Process case TT20220606-0416 - Site is 
down_MainTT - Jangal_U ,
SLA- 1" onkeypress="if(hasKeyCode(event,'KEYCODE_ENTER')) { 
sendEvent('openassignment','mx145','5');}" class="text pkr" 
href="javascript:sendEvent('openassignment','mx145','5')">Input Process case 
TT20220606-0416 - Site is down_MainTT - Jangal_U ,SLA- 1
</a>
</td>
<td class="text ibr">TTINFONEW</td>
<td class="text ibr"></td>
<td class="text ibr">2022-06-06 21:54</td>
<td class="text ri">
<a tabindex="0" title="Route" onkeypress="if(hasKeyCode(event,'KEYCODE_ENTER')) { 
sendEvent('routeassignment','mx145','5');}" class="text ri" 
href="javascript:sendEvent('routeassignment','mx145','5')">
<img src="../webclient/skins/tivoli09/images/nav_icon_route.gif" 
border="0" alt="Route">
</a>
</td>
</tr>

This is code snippet of links WITHOUT "Input Process case" value

<tr valign="top">
<td valign="middle" class="text ibr">
&nbsp;
<a tabindex="0" title="TT20220607-3549 - Site Abis control link broken - 
Kangurt is down,SLA- 2" onkeypress="if(hasKeyCode(event,'KEYCODE_ENTER')) { 
sendEvent('openassignment','mx145','4');}" class="text pkr" 
href="javascript:sendEvent('openassignment','mx145','4')">
TT20220607-3549 - Site Abis control link broken - Kangurt is down,SLA- 2</a></td>
<td class="text ibr">TTINFONEW</td>
<td class="text ibr"></td>
<td class="text ibr">2022-06-07 15:56</td>
<td class="text ri">
<a tabindex="0" title="Route" onkeypress="if(hasKeyCode(event,'KEYCODE_ENTER')) { 
sendEvent('routeassignment','mx145','4');}" class="text ri" 
href="javascript:sendEvent('routeassignment','mx145','4')">
<img src="../webclient/skins/tivoli09/images/nav_icon_route.gif" border="0" alt="Route">
</a>
</td>
</tr>

My question for Omid

enter image description here

Solution

Given the <a> elements in question seem to have a title attribute, you could use the ^= Attribute selector to accomplish this. This is saying "find all elements that do not have a title attribute that starts with … ":

document.querySelectorAll("a:not([title^='Input Process case'])")

Or if that’s not always the case, you can grab all of them then filter their textContent:

Array.from(document.querySelectorAll("a")).filter((a) => {
  return !a.textContent.includes('Input Process case'))
}

Here’s a snippet showing both working.

const countWithTitle = document.querySelectorAll("a:not([title^='Input Process case'])")
const countWithText = Array.from(document.querySelectorAll("a")).filter((a) => !a.textContent.includes('Input Process case'))


console.log(countWithTitle.length)
console.log(countWithText.length)
<table>
  <tr valign="top">
    td valign="middle" class="text ibr"> &nbsp;
    <a tabindex="0" title="Input Process case TT20220606-0416 - Site is 
down_MainTT - Jangal_U ,
SLA- 1" onkeypress="if(hasKeyCode(event,'KEYCODE_ENTER')) { 
sendEvent('openassignment','mx145','5');}" class="text pkr" href="javascript:sendEvent('openassignment','mx145','5')">Input Process case
      TT20220606-0416 - Site is down_MainTT - Jangal_U ,SLA- 1
    </a>
    </td>
    <td class="text ibr">TTINFONEW</td>
    <td class="text ibr"></td>
    <td class="text ibr">2022-06-06 21:54</td>
    <td class="text ri">
      <a tabindex="0" title="Route" onkeypress="if(hasKeyCode(event,'KEYCODE_ENTER')) { 
sendEvent('routeassignment','mx145','5');}" class="text ri" href="javascript:sendEvent('routeassignment','mx145','5')">
        <img src="../webclient/skins/tivoli09/images/nav_icon_route.gif" border="0" alt="Route">
      </a>
    </td>
  </tr>
  <tr valign="top">
    <td valign="middle" class="text ibr">
      &nbsp;
      <a tabindex="0" title="TT20220607-3549 - Site Abis control link broken - 
Kangurt is down,SLA- 2" onkeypress="if(hasKeyCode(event,'KEYCODE_ENTER')) { 
sendEvent('openassignment','mx145','4');}" class="text pkr" href="javascript:sendEvent('openassignment','mx145','4')">
        TT20220607-3549 - Site Abis control link broken - Kangurt is down,SLA- 2</a>
    </td>
    <td class="text ibr">TTINFONEW</td>
    <td class="text ibr"></td>
    <td class="text ibr">2022-06-07 15:56</td>
    <td class="text ri">
      <a tabindex="0" title="Route" onkeypress="if(hasKeyCode(event,'KEYCODE_ENTER')) { 
sendEvent('routeassignment','mx145','4');}" class="text ri" href="javascript:sendEvent('routeassignment','mx145','4')">
        <img src="../webclient/skins/tivoli09/images/nav_icon_route.gif" border="0" alt="Route">
      </a>
    </td>
  </tr>
</table>

Answered By – Omid

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.