0

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

1 Answers1

1

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>
omid
  • 1,146
  • 1
  • 7
  • 17
  • But how to make it exclude values from the 'Input Process case'? if i put "!=" it does not work – Shahkumar41 Jun 08 '22 at 08:40
  • Sir, i post image-question above, please take a look – Shahkumar41 Jun 08 '22 at 08:53
  • For your second question, just use `document.querySelectorAll('a.text.pkr')` – omid Jun 08 '22 at 08:55
  • how do I use two conditions? I need something like ```Array.from(document.querySelectorAll("a")).filter((a) => { var qw = !a.text Content.includes('Input Process case'); return qw.classList.contains('.text pkr'); })``` – Shahkumar41 Jun 08 '22 at 09:04
  • See this answer: [javascript filter array multiple conditions](https://stackoverflow.com/questions/31831651/javascript-filter-array-multiple-conditions) – omid Jun 08 '22 at 09:06
  • could you please help, how to return length of array qw? ```Array.from(document.querySelectorAll("a.text.pkr")).filter((a) => { var qw = !a.textContent.includes('Input Process case'); return qw.length; })``` – Shahkumar41 Jun 08 '22 at 09:17