none
vb.net GetElementByid from already opened pages in internet explorer RRS feed

  • Question

  • im working on project (vb.net) that read text from website and save it to .sdf database and then print it out

    so far i can read elements in the first internet explorer page that opened from my project , the first page has link to choice the language when i click on it it open another window (not tab) and here is my problem cuze i cannot read any elements value from the second internet explorer window

    How i can tel my application which internet explorer window need to get elements value from ?

    here is my code

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
        ie = New SHDocVw.InternetExplorer
        With ie
            .Visible = True
            .Navigate("http://11.2.114.155/")
            Do Until Not .Busy And .ReadyState = 4
            Loop
            doc = ie.Document
        End With
        ie = Nothing
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    
            elements = doc.getElementsByName("AccountNo")
            elements1 = doc.getElementsByName("AcctTitle")
            elements2 = doc.getElementsByName("NamBenef")
            elements3 = doc.getElementsByName("TCY_Amount")
            elements4 = doc.getElementsByName("InstrDate")
    
            nachnameValueInput = elements(0)
            nachnameValueInput1 = elements1(0)
            nachnameValueInput2 = elements2(0)
            nachnameValueInput3 = elements3(0)
            nachnameValueInput4 = elements4(0)
     On Error Resume Next
    
            Dim DM1 As DataTable = ds.Tables("CheqDetail")
            Dim DM2 As DataView = DM1.DefaultView
            Dim DM As DataRowView = DM2.AddNew()
            Dim SQ As Integer = 1
            If dv.Count > 0 Then SQ = dv.Item(0).Item("SQ") + 1
            DM("SQ") = SQ

    If IsDBNull(nachnameValueInput.getAttribute("Value").ToString) = False Then DM("AccNUM") = nachnameValueInput.getAttribute("Value").ToString If IsDBNull(nachnameValueInput1.getAttribute("Value").ToString) = False Then DM("AccNAM") = nachnameValueInput1.getAttribute("Value").ToString If IsDBNull(nachnameValueInput2.getAttribute("Value").ToString) = False Then DM("BinfNAM") = nachnameValueInput2.getAttribute("Value").ToString If IsDBNull(nachnameValueInput3.getAttribute("Value").ToString) = False Then DM("AmountNUM") = Val(nachnameValueInput3.getAttribute("Value").ToString)

       If IsDBNull(nachnameValueInput3.getAttribute("Value").ToString) = False Then DM("AmountCHR") = ConvertNumbersToWords(Convert.ToDecimal(Val(nachnameValueInput3.getAttribute("Value")).ToString), "دينار", "درهم", "فقط(", ")لاغير.")
            If IsDBNull(nachnameValueInput.getAttribute("Value").ToString) = False Then
                If IsDate(nachnameValueInput4.getAttribute("Value").ToString) = True Then
                    DM("IssueDate") = nachnameValueInput4.getAttribute("Value").ToString
                    Me.DateTimePicker1.Value = nachnameValueInput4.getAttribute("Value").ToString
                End If

    Sunday, September 23, 2018 7:04 AM

Answers

  • Hi,

    traversing IE forms

    reference SHDocVw.dll and Shell32.dll in System32

    Imports SHDocVw
    Imports Shell32
    'Imports IE
    
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            lvwIE.View = View.Details
            lvwIE.Columns.Add("URL")
            lvwIE.Columns.Add("Name")
            lvwIE.Columns(0).Width = 300
            lvwIE.Columns(1).AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize)
            Dim test As SHDocVw.ShellWindows = New SHDocVw.ShellWindows()
            Dim lines As String() = New String(test.Count - 1) {}
    
            For i As Integer = 0 To test.Count - 1
                Dim ie As SHDocVw.InternetExplorer = Nothing
                ie = TryCast(test.Item(i), SHDocVw.InternetExplorer)
                Dim prv As String = ie.LocationURL.Substring(0, 4).ToLower()
    
                If prv = "http" Then
                    Dim lvt As ListViewItem = New ListViewItem()
                    lvt.SubItems(0).Text = ie.LocationURL
                    lvt.SubItems.Add(ie.LocationName)
                    lvwIE.Items.Add(lvt)
                End If
            Next
        End Sub
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Osama Shultame Tuesday, September 25, 2018 1:50 PM
    Monday, September 24, 2018 5:48 AM

All replies

  • Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
        ie = New SHDocVw.InternetExplorer
        With ie
            .Visible = True
            .Navigate("http://11.2.114.155/")
            Do Until Not .Busy And .ReadyState = 4
            Loop
            doc = ie.Document
        End With
        ie = Nothing
    End Sub


    Sunday, September 23, 2018 7:05 AM
  • Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    
            elements = doc.getElementsByName("AccountNo")
            elements1 = doc.getElementsByName("AcctTitle")
            elements2 = doc.getElementsByName("NamBenef")
            elements3 = doc.getElementsByName("TCY_Amount")
            elements4 = doc.getElementsByName("InstrDate")
    
            nachnameValueInput = elements(0)
            nachnameValueInput1 = elements1(0)
            nachnameValueInput2 = elements2(0)
            nachnameValueInput3 = elements3(0)
            nachnameValueInput4 = elements4(0)
    
           
    Sunday, September 23, 2018 7:07 AM
  •  On Error Resume Next
    
            Dim DM1 As DataTable = ds.Tables("CheqDetail")
            Dim DM2 As DataView = DM1.DefaultView
            Dim DM As DataRowView = DM2.AddNew()
            Dim SQ As Integer = 1
            If dv.Count > 0 Then SQ = dv.Item(0).Item("SQ") + 1
            DM("SQ") = SQ
           
    Sunday, September 23, 2018 7:08 AM
  • 
            If IsDBNull(nachnameValueInput3.getAttribute("Value").ToString) = False Then DM("AmountCHR") = ConvertNumbersToWords(Convert.ToDecimal(Val(nachnameValueInput3.getAttribute("Value")).ToString), "دينار", "درهم", "فقط(", ")لاغير.")
            If IsDBNull(nachnameValueInput.getAttribute("Value").ToString) = False Then
                If IsDate(nachnameValueInput4.getAttribute("Value").ToString) = True Then
                    DM("IssueDate") = nachnameValueInput4.getAttribute("Value").ToString
                    Me.DateTimePicker1.Value = nachnameValueInput4.getAttribute("Value").ToString
                End If
        

    Sunday, September 23, 2018 7:08 AM
  •     End If
    
            DM("ApproveNUM") = TextBox9.Text + TextBox8.Text + TextBox7.Text
            DM.EndEdit()
            cn.Open()
            ad.Update(ds, "CheqDetail")
            cn.Close()
            ds.AcceptChanges()
    
            MsgBox("تم جلب البيانات بنجاح")
    
    
            Me.BindingSource1.Position = Me.BindingSource1.Count - 1
        End With
    End Sub
    Sunday, September 23, 2018 7:08 AM
  • Hi Osama,

    Your issue is related to vb.net, this forum is discussing about wpf question, I will move this thread to vb.net forum for professional help.

    Thanks for your understanding.

    Best Regards,

    cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 24, 2018 1:38 AM
    Moderator
  • Hi,

    traversing IE forms

    reference SHDocVw.dll and Shell32.dll in System32

    Imports SHDocVw
    Imports Shell32
    'Imports IE
    
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            lvwIE.View = View.Details
            lvwIE.Columns.Add("URL")
            lvwIE.Columns.Add("Name")
            lvwIE.Columns(0).Width = 300
            lvwIE.Columns(1).AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize)
            Dim test As SHDocVw.ShellWindows = New SHDocVw.ShellWindows()
            Dim lines As String() = New String(test.Count - 1) {}
    
            For i As Integer = 0 To test.Count - 1
                Dim ie As SHDocVw.InternetExplorer = Nothing
                ie = TryCast(test.Item(i), SHDocVw.InternetExplorer)
                Dim prv As String = ie.LocationURL.Substring(0, 4).ToLower()
    
                If prv = "http" Then
                    Dim lvt As ListViewItem = New ListViewItem()
                    lvt.SubItems(0).Text = ie.LocationURL
                    lvt.SubItems.Add(ie.LocationName)
                    lvwIE.Items.Add(lvt)
                End If
            Next
        End Sub
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Osama Shultame Tuesday, September 25, 2018 1:50 PM
    Monday, September 24, 2018 5:48 AM
  • Alex , Thx so much for your help and time 

    I will try and get back to you

    Regards, Osama

    Monday, September 24, 2018 12:47 PM
  • Hey Alex,

    I tried you code but still have problem

    my problem is with ie.doc it returns NULL because it cannot find the value of the element that im locking for with 2 internet explorer window

    also

    vwIE do it mean "Dim IvwIE As InternetExplorer" as i got this error message 

    'lvwIE' is not declared. It may be inaccessible due to its protection level.

    Regards, Osama



    Monday, September 24, 2018 2:20 PM
  • Hi,

    'lvwIE' is a listview control

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 25, 2018 1:49 AM
  • Alex

    Thx so much for your code, its working grate

    Still have ltel problem , When you open internet explorer window and open another one by right click on internet explorer icon your code is working fine and it gets all the elements value without any problem

    But when you open internet explorer window and click on any link inside the first window (Not Right Click to Open new window) your code is failed cuze loop stops ,   If ie.LocationName value it gives me just the first window value not the second one

    Regards

    Tuesday, September 25, 2018 1:50 PM