Sam
Sam

Reputation: 13

How to check if a text exist in IE webpage under div class/TR/TD Class?

I have tried finding a solution to my problem for few days already - somehow I just don't manage to find a working solution.

Unfortunately I cannot give the URL for the webpage that I have as it would require a login and password - which I cannot share.

I have the VBA code already doing me everything, login into the webpage - proving the proper information inside the page and clicking validate button. But the problem is that I should then see if the below text appears: ENQUADRAMENTO EM VIGOR - if yes, I will continue slightly differently the process and if not then differently.

Now below is the code from the webpage:

            <tr>
                <td>
                    <table cellpadding="4" border="0" width="100%">
                        <tbody><tr>
                            <td class="fieldTitleBold" style="width=30%">Enquadramento em IVA</td>

                            <td class="fieldValue" colspan="3">NORMAL TRIMESTRAL</td>

                        </tr>
                        <tr>
                            <td style="width=10%" class="fieldTitleBold">Situação</td>

                            <td class="fieldValue" colspan="3">ENQUADRAMENTO EM VIGOR</td>

                        </tr>

                    </tbody></table>                        
                </td>
            </tr>

I have tried many different ways and the latest I tried is with byclassname (this worked for me in a different website for similar purpose) but doesn't work here for some reason:

Set doc = ie.document
Set htmTable = doc.getElementsByClassName("ENQUADRAMENTO EM VIGOR")(0)
If Not htmTable Is Nothing Then 

'continue depending if the text was found or not in different ways

Upvotes: 0

Views: 216

Answers (2)

QHarr
QHarr

Reputation: 84465

ENQUADRAMENTO EM VIGOR is the .innerText value not the class name. The class value is fieldValue and is associated with a td (table cell) element.

This is pretty easy if it only occurs once. Use Instr to see if present in page html

If Instr(ie.document.body.innerHTML,"ENQUADRAMENTO EM VIGOR") > 0 Then

Otherwise, you can gather a nodeList of td elements with that class name and loop testing the .innerText

Dim classes As Object, i As Long
Set classes = ie.document.querySelectorAll("td.fieldValue")
For i = 0 To classes.Length - 1
   If classes.item(i).innerText = "ENQUADRAMENTO EM VIGOR" Then
       'do something
       'Exit For ....
   End If
End Sub

Upvotes: 1

karthick s
karthick s

Reputation: 54

$(document).ready(function() { 

    var lenfV = document.querySelectorAll(".fieldValue");
    for(let i=0;i<lenfV.length;i++) {
      if(lenfV[i].innerHTML == "ENQUADRAMENTO EM VIGOR") {
          console.log("is there");
      }
      //else {console.log(213423);}
    }

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p> I think, The below option will help you</p>
<table>

<tr>
                <td>
                    <table cellpadding="4" border="0" width="100%">
                        <tbody><tr>
                            <td class="fieldTitleBold" style="width=30%">Enquadramento em IVA</td>

                            <td class="fieldValue" colspan="3">NORMAL TRIMESTRAL</td>

                        </tr>
                        <tr>
                            <td style="width=10%" class="fieldTitleBold">Situação</td>

                            <td class="fieldValue" colspan="3">ENQUADRAMENTO EM VIGOR</td>
                        </tr>

                    </table>                        
                </td>
            </tr>
</table>

Upvotes: 0

Related Questions