I am trying to extract the innertext under the 'span' class from a IE browser, but facing an issue. Below is the HTML code
1st html snippet
<div class="SectionStart" style="display: block;" oraload="oraDisplayNone(item,'newDev','Y','=')" oraInitDisplayStyle="block">
<label oramdlabel="CM_SN">Serial Number</label>
<!--style tag has been added-->
<span class="oraDefault" style="left: -5px; top: 4.5px; position: relative;" orafield="MSerialNumber" oraType="string;precision:20" oraErrorElement="mSerialNumber">G4A001</span>
</div>
2nd html snippet
<div class="SectionStart">
<label oramdlabel="CM_SN">Serial Number:</label>
<!--style tag has been added-->
<span class="oraDefault" style="left: -5px; top: 4.5px; position: relative;" orafield="MSerialNumber" oraType="string;precision:20" oraErrorElement="mSerialNumber">E5W807</span>
</div>
Here the issue is as per below code ,while trying to fetch the 2nd value "E5W807", I am only fetching the not required value "G4A001".
Please guide how can I tackle the problem of ONLY extracting the text "E5W807".
Set objSubCollec = objCollection(0).contentWindow.document.getElementById("Page")
Set objElement = objSubCollec.contentWindow.document.getElementById("Frame_4")
objElement.Focus
Set objElement1 = objElement.contentWindow.document
Set elm2 = objElement1.getElementsByTagName("span")
For Each e1 In elm2
If e1.getAttribute("orafield") = "MSerialNumber" Then
temp = e1.innerText
'MsgBox temp
Worksheets("Sheet1").Range("B6") = temp
Exit For
End If
Next
Maybe Try this:
It will print all the found numbers in succession from B6.
Set objSubCollec = objCollection(0).contentWindow.document.getElementById("Page")
Set objElement = objSubCollec.contentWindow.document.getElementById("Frame_4")
objElement.Focus
Set objElement1 = objElement.contentWindow.document
Set elm2 = objElement1.getElementsByTagName("span")
i = 6
For Each e1 In elm2
If e1.getAttribute("orafield") = "MSerialNumber" Then
temp = e1.innerText
Worksheets("Sheet1").Range("B & i") = temp
i = i + 1
End If
Next
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.