Constancia

VB_CLS_NaviWeb2

Jul 12th, 2015
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 28.81 KB | None | 0 0
  1. Imports System.Windows.Forms
  2. Imports SHDocVw
  3. Imports mshtml
  4.  
  5. Public Class NaviWeb2
  6.  
  7.     Public oTabla As IHTMLTable, Tabla_TR As IHTMLTableRow, Tabla_TD As IHTMLTableCell
  8.     Private Doc As mshtml.HTMLDocument
  9.     Public oFrame As IHTMLFrameBase
  10.  
  11.     Declare Sub Sleep Lib "kernel32.dll" (ByVal Milliseconds As Integer)
  12.  
  13.     Public Sub New(oNav As SHDocVw.InternetExplorer)
  14.         oNavegador = oNav
  15.         CargaVariables()
  16.  
  17.     End Sub
  18.  
  19. #Region "PROPIEDADES"
  20.  
  21.  
  22.     Private _sError As String
  23.     Public Property sError() As String
  24.         Get
  25.             Return _sError
  26.         End Get
  27.         Set(value As String)
  28.             _sError = value
  29.         End Set
  30.     End Property
  31.  
  32.     Private _tSleep As Integer
  33.     Public Property tSleep() As Integer
  34.         Get
  35.             Return _tSleep
  36.         End Get
  37.         Set(ByVal value As Integer)
  38.             _tSleep = value
  39.         End Set
  40.     End Property
  41.  
  42.     Private WithEvents oNavegador As SHDocVw.InternetExplorer
  43.     Public Property Navegador() As SHDocVw.InternetExplorer
  44.         Get
  45.             Return oNavegador
  46.         End Get
  47.         Set(oNav As SHDocVw.InternetExplorer)
  48.             oNavegador = oNav
  49.         End Set
  50.     End Property
  51.  
  52.     Private _bNaviScriptError As Boolean
  53.     Public Property bNaviScriptError() As Boolean
  54.         Get
  55.             Return _bNaviScriptError
  56.         End Get
  57.         Set(ByVal value As Boolean)
  58.             _bNaviScriptError = value
  59.         End Set
  60.     End Property
  61.  
  62.     Private _DocNavi As IHTMLDocument3
  63.     Public Property DocNavi() As IHTMLDocument3
  64.         Get
  65.             Return _DocNavi
  66.         End Get
  67.         Set(oDoc As IHTMLDocument3)
  68.             _DocNavi = oDoc
  69.         End Set
  70.     End Property
  71.  
  72.     Private _DocActivo As mshtml.HTMLDocument
  73.     Public Property DocActivo() As mshtml.HTMLDocument
  74.         Get
  75.             Return _DocActivo
  76.         End Get
  77.         Set(oDoc As mshtml.HTMLDocument)
  78.             _DocActivo = oDoc
  79.         End Set
  80.     End Property
  81.  
  82.     Private _DocActivo2 As IHTMLDocument3
  83.     Public Property DocActivo2() As IHTMLDocument3
  84.         Get
  85.             Return _DocActivo2
  86.         End Get
  87.         Set(oDoc As IHTMLDocument3)
  88.             _DocActivo2 = oDoc
  89.         End Set
  90.     End Property
  91.  
  92.     Private _bCompleto As Boolean
  93.     Public Property bCompleto() As Boolean
  94.         Get
  95.             Return _bCompleto
  96.         End Get
  97.         Set(ByVal value As Boolean)
  98.             _bCompleto = value
  99.         End Set
  100.     End Property
  101.  
  102.     Private oFormu As IHTMLFormElement
  103.     Public Property Formu() As IHTMLFormElement
  104.         Get
  105.             Return oFormu
  106.         End Get
  107.         Set(oForm As IHTMLFormElement)
  108.             oFormu = oForm
  109.         End Set
  110.     End Property
  111.  
  112.     Private _oElemento As IHTMLElement
  113.     Public Property oElemento() As IHTMLElement
  114.         Get
  115.             Return _oElemento
  116.         End Get
  117.         Set(Obj As IHTMLElement)
  118.             _oElemento = Obj
  119.         End Set
  120.     End Property
  121.  
  122.     Private _oElemento2 As HtmlElement
  123.     Public Property oElemento2() As HtmlElement
  124.         Get
  125.             Return _oElemento2
  126.         End Get
  127.         Set(Obj As HtmlElement)
  128.             _oElemento2 = Obj
  129.         End Set
  130.     End Property
  131.  
  132.     Private oEvento As IHTMLEventObj
  133.     Public Property Evento() As IHTMLEventObj
  134.         Get
  135.             'Return oEvento
  136.             Return _DocActivo.CreateEventObject()
  137.         End Get
  138.         Set(Obj As IHTMLEventObj)
  139.             oEvento = Obj
  140.         End Set
  141.     End Property
  142.  
  143.     Private oCombo As IHTMLSelectElement
  144.     Public Property Combo() As IHTMLSelectElement
  145.         Get
  146.             Return oCombo
  147.         End Get
  148.         Set(Obj As IHTMLSelectElement)
  149.             oCombo = Obj
  150.         End Set
  151.     End Property
  152.  
  153.     Private _L_oElementos As List(Of IHTMLElement)
  154.     Public Property L_Elementos() As List(Of IHTMLElement)
  155.         Get
  156.             Return _L_oElementos
  157.         End Get
  158.         Set(Obj As List(Of IHTMLElement))
  159.             _L_oElementos = Obj
  160.         End Set
  161.     End Property
  162.  
  163.     Private bbComboValor As Boolean
  164.     Public Property bComboValor As Boolean
  165.         Get
  166.             Return bbComboValor
  167.         End Get
  168.         Set(b As Boolean)
  169.             bbComboValor = b
  170.         End Set
  171.     End Property
  172.  
  173.     '************* PROPIEDADES DE LAS VENTANA EMERGENTE 1
  174.     Private oNavegador_POP As SHDocVw.InternetExplorer
  175.     Public Property Navegador_POP() As SHDocVw.InternetExplorer
  176.         Get
  177.             Return oNavegador_POP
  178.         End Get
  179.         Set(oNav As SHDocVw.InternetExplorer)
  180.             oNavegador_POP = oNav
  181.         End Set
  182.     End Property
  183.  
  184.     Private _DocActivo_POP As mshtml.HTMLDocument
  185.     Public Property DocActivo_POP() As mshtml.HTMLDocument
  186.         Get
  187.             Return _DocActivo_POP
  188.         End Get
  189.         Set(oDoc As mshtml.HTMLDocument)
  190.             _DocActivo_POP = oDoc
  191.         End Set
  192.     End Property
  193.  
  194.     Private _DocActivo2_POP As IHTMLDocument3
  195.     Public Property DocActivo2_POP() As IHTMLDocument3
  196.         Get
  197.             Return _DocActivo2_POP
  198.         End Get
  199.         Set(oDoc As IHTMLDocument3)
  200.             _DocActivo2_POP = oDoc
  201.         End Set
  202.     End Property
  203.  
  204.     Private _bCompleto_POP As Boolean
  205.     Public Property bCompleto_POP() As Boolean
  206.         Get
  207.             Return _bCompleto_POP
  208.         End Get
  209.         Set(ByVal value As Boolean)
  210.             _bCompleto_POP = value
  211.         End Set
  212.     End Property
  213.  
  214.     Private _bPop As Boolean
  215.     Public Property bPop() As Boolean
  216.         Get
  217.             Return _bPop
  218.         End Get
  219.         Set(value As Boolean)
  220.             _bPop = value
  221.         End Set
  222.     End Property
  223.  
  224.     Private _bPopVisible As Boolean
  225.     Public Property bPopVisible() As Boolean
  226.         Get
  227.             Return _bPopVisible
  228.         End Get
  229.         Set(value As Boolean)
  230.             _bPopVisible = value
  231.         End Set
  232.     End Property
  233.  
  234.     Private _TituloPop As String
  235.     Public Property TituloPop() As String
  236.         Get
  237.             Return _TituloPop
  238.         End Get
  239.         Set(value As String)
  240.             _TituloPop = value
  241.         End Set
  242.     End Property
  243.  
  244.     '************* PROPIEDADES DE LAS VENTANA EMERGENTE 2
  245.  
  246.     'Private oNavegador_POP2 As AxSHDocVw.AxWebBrowser
  247.     'Public Property Navegador_POP2() As AxSHDocVw.AxWebBrowser
  248.     '    Get
  249.     '        Return oNavegador_POP2
  250.     '    End Get
  251.     '    Set(oNav As AxSHDocVw.AxWebBrowser)
  252.     '        oNavegador_POP2 = oNav
  253.     '    End Set
  254.     'End Property
  255.  
  256.     'Private _DocActivo_POP2 As IHTMLDocument3
  257.     'Public Property DocActivo_POP2() As IHTMLDocument3
  258.     '    Get
  259.     '        Return _DocActivo_POP2
  260.     '    End Get
  261.     '    Set(oDoc As IHTMLDocument3)
  262.     '        _DocActivo_POP2 = oDoc
  263.     '    End Set
  264.     'End Property
  265.  
  266.     '************* PROPIEDADES DE LAS VENTANA EMERGENTE 2
  267.     Private oNavegador_POP2 As SHDocVw.InternetExplorer
  268.     Public Property Navegador_POP2() As SHDocVw.InternetExplorer
  269.         Get
  270.             Return oNavegador_POP2
  271.         End Get
  272.         Set(oNav As SHDocVw.InternetExplorer)
  273.             oNavegador_POP2 = oNav
  274.         End Set
  275.     End Property
  276.  
  277.     Private _DocActivo_POP2 As mshtml.HTMLDocument
  278.     Public Property DocActivo_POP2() As mshtml.HTMLDocument
  279.         Get
  280.             Return _DocActivo_POP2
  281.         End Get
  282.         Set(oDoc As mshtml.HTMLDocument)
  283.             _DocActivo_POP2 = oDoc
  284.         End Set
  285.     End Property
  286.  
  287.     Private _DocActivo2_POP2 As IHTMLDocument3
  288.     Public Property DocActivo2_POP2() As IHTMLDocument3
  289.         Get
  290.             Return _DocActivo2_POP2
  291.         End Get
  292.         Set(oDoc As IHTMLDocument3)
  293.             _DocActivo2_POP2 = oDoc
  294.         End Set
  295.     End Property
  296.  
  297.     Private _bCompleto_POP2 As Boolean
  298.     Public Property bCompleto_POP2() As Boolean
  299.         Get
  300.             Return _bCompleto_POP2
  301.         End Get
  302.         Set(ByVal value As Boolean)
  303.             _bCompleto_POP2 = value
  304.         End Set
  305.     End Property
  306.  
  307.     Private _bPop2 As Boolean
  308.     Public Property bPop2() As Boolean
  309.         Get
  310.             Return _bPop2
  311.         End Get
  312.         Set(value As Boolean)
  313.             _bPop2 = value
  314.         End Set
  315.     End Property
  316.  
  317.     Private _bPopVisible2 As Boolean
  318.     Public Property bPopVisible2() As Boolean
  319.         Get
  320.             Return _bPopVisible2
  321.         End Get
  322.         Set(value As Boolean)
  323.             _bPopVisible2 = value
  324.         End Set
  325.     End Property
  326.  
  327.     Private _TituloPop2 As String
  328.     Public Property TituloPop2() As String
  329.         Get
  330.             Return _TituloPop2
  331.         End Get
  332.         Set(value As String)
  333.             _TituloPop2 = value
  334.         End Set
  335.     End Property
  336.  
  337.  
  338.     '************* PROPIEDADES DE LAS VENTANA EMERGENTE 3
  339.  
  340.     'Private oNavegador_POP2 As AxSHDocVw.AxWebBrowser
  341.     'Public Property Navegador_POP2() As AxSHDocVw.AxWebBrowser
  342.     '    Get
  343.     '        Return oNavegador_POP2
  344.     '    End Get
  345.     '    Set(oNav As AxSHDocVw.AxWebBrowser)
  346.     '        oNavegador_POP2 = oNav
  347.     '    End Set
  348.     'End Property
  349.  
  350.     'Private _DocActivo_POP2 As IHTMLDocument3
  351.     'Public Property DocActivo_POP2() As IHTMLDocument3
  352.     '    Get
  353.     '        Return _DocActivo_POP2
  354.     '    End Get
  355.     '    Set(oDoc As IHTMLDocument3)
  356.     '        _DocActivo_POP2 = oDoc
  357.     '    End Set
  358.     'End Property
  359.  
  360.     Private _bPop3 As Boolean
  361.     Public Property bPop3() As Boolean
  362.         Get
  363.             Return _bPop3
  364.         End Get
  365.         Set(value As Boolean)
  366.             _bPop3 = value
  367.         End Set
  368.     End Property
  369.  
  370.     Private _bPopVisible3 As Boolean
  371.     Public Property bPopVisible3() As Boolean
  372.         Get
  373.             Return _bPopVisible3
  374.         End Get
  375.         Set(value As Boolean)
  376.             _bPopVisible3 = value
  377.         End Set
  378.     End Property
  379.  
  380.     Private _TituloPop3 As String
  381.     Public Property TituloPop3() As String
  382.         Get
  383.             Return _TituloPop3
  384.         End Get
  385.         Set(value As String)
  386.             _TituloPop3 = value
  387.         End Set
  388.     End Property
  389.  
  390. #End Region
  391.  
  392. #Region "MÉTODOS PÚBLICOS"
  393.  
  394.     Public Sub IniciaNavi()
  395.  
  396.         oNavegador = New SHDocVw.InternetExplorer
  397.         oNavegador.Silent = True
  398.         oNavegador.Visible = True
  399.  
  400.     End Sub
  401.  
  402.     Public Sub MataNavi()
  403.         oNavegador.Quit()
  404.         oNavegador = Nothing
  405.     End Sub
  406.  
  407.     Public Sub Navegar(sURL As String)
  408.         oNavegador.Navigate(sURL)
  409.         ' While Not _bCompleto : Application.DoEvents() : End While
  410.         EsperaCarga(3)
  411.         _DocNavi = oNavegador.Document
  412.     End Sub
  413.  
  414.     ''' <summary>
  415.     '''
  416.     ''' </summary>
  417.     ''' <param name="iEstado">3-Interactive / 4-Complete</param>
  418.     ''' <remarks></remarks>
  419.     Public Sub EsperaCarga(iEstado As Integer)
  420.  
  421.         Sleep(_tSleep)
  422.  
  423.         While oNavegador.Busy Or oNavegador.ReadyState <> iEstado And oNavegador.ReadyState <> 4
  424.             Application.DoEvents()
  425.         End While
  426.  
  427.     End Sub
  428.  
  429.     Public Sub Espera(Segundos As Integer)
  430.  
  431.         Sleep(Segundos * 1000)
  432.  
  433.         'For i As Integer = 0 To Num * 25000
  434.         '    Application.DoEvents()
  435.         'Next
  436.  
  437.     End Sub
  438.  
  439.     ''' <summary>
  440.     ''' Asigna el DocActivo al documento en el que se encuentra el Elemento buscado
  441.     ''' </summary>
  442.     ''' <param name="Tipo"></param>
  443.     ''' <param name="Id"></param>
  444.     ''' <param name="Nombre"></param>
  445.     ''' <param name="Texto"></param>
  446.     ''' <param name="bTextoExacto"></param>
  447.     ''' <param name="Atributo"></param>
  448.     ''' <param name="ValAtributo"></param>
  449.     ''' <param name="bAtributoExacto"></param>
  450.     ''' <param name="bCol"></param>
  451.     ''' <param name="sHTML"></param>
  452.     ''' <param name="bHTMLExacto"></param>
  453.     ''' <returns></returns>
  454.     ''' <remarks></remarks>
  455.     Public Function DameDoc(Tipo As String, Optional Id As String = "", _
  456.                             Optional Nombre As String = "", _
  457.                             Optional Texto As String = "", _
  458.                             Optional bTextoExacto As Boolean = True, _
  459.                             Optional Atributo As String = "", _
  460.                             Optional ValAtributo As String = "", _
  461.                             Optional bAtributoExacto As Boolean = True,
  462.                             Optional bCol As Boolean = False, _
  463.                             Optional sHTML As String = "", _
  464.                             Optional bHTMLExacto As Boolean = True) As Boolean
  465.  
  466.         DameDoc = False
  467.  
  468.         Dim Docu As IHTMLDocument3
  469.         Dim DocuTemp1 As IHTMLDocument3, DocuTemp2 As IHTMLDocument3, DocuTemp3 As IHTMLDocument3, DocuTemp4 As IHTMLDocument3, DocuTemp5 As IHTMLDocument3
  470.         Dim iFrame1 As Integer, iFrame2 As Integer, iFrame3 As Integer, iFrame4 As Integer, iFrame5 As Integer
  471.  
  472.         Docu = oNavegador.Document
  473.  
  474.         '************************************************************************>> EL DOCUMENTO NO TIENE FRAMES
  475.         If Docu.frames.length = 0 Then
  476.  
  477.             If ExisteElemento(Docu, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  478.                 _DocActivo = Docu : Return True
  479.             End If
  480.  
  481.         Else
  482.             '***********************************************************************************>> FRAMES NIVEL1
  483.             For iFrame1 = 0 To Docu.frames.length - 1
  484.  
  485.                 DocuTemp1 = Docu.frames(iFrame1).document
  486.                 If ExisteElemento(DocuTemp1, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  487.                     _DocActivo = DocuTemp1 : Return True
  488.                 End If
  489.  
  490.                 If DocuTemp1.frames.length > 0 Then
  491.  
  492.                     '****************************************************************************>> FRAMES NIVEL2
  493.                     For iFrame2 = 0 To DocuTemp1.frames.length - 1
  494.  
  495.                         DocuTemp2 = DocuTemp1.frames(iFrame2).document
  496.                         If ExisteElemento(DocuTemp2, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  497.                             _DocActivo = DocuTemp2 : Return True
  498.                         End If
  499.  
  500.                         If DocuTemp2.frames.length > 0 Then
  501.                             '**********************************************************************>> FRAMES NIVEL3
  502.                             For iFrame3 = 0 To DocuTemp2.frames.length - 1
  503.  
  504.                                 DocuTemp3 = DocuTemp2.frames(iFrame3).document
  505.                                 If ExisteElemento(DocuTemp3, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  506.                                     _DocActivo = DocuTemp3 : Return True
  507.                                 End If
  508.  
  509.                                 If DocuTemp3.frames.length > 0 Then
  510.  
  511.                                     '***************************************************************>> FRAMES NIVEL4
  512.                                     For iFrame4 = 0 To DocuTemp3.frames.length - 1
  513.  
  514.                                         DocuTemp4 = DocuTemp3.frames(iFrame4).document
  515.                                         If ExisteElemento(DocuTemp4, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  516.                                             _DocActivo = DocuTemp4 : Return True
  517.                                         End If
  518.  
  519.                                         If DocuTemp4.frames.length > 0 Then
  520.  
  521.                                             '*******************************************************>> FRAMES NIVEL5
  522.                                             For iFrame5 = 0 To DocuTemp4.frames.length - 1
  523.  
  524.                                                 DocuTemp5 = DocuTemp4.frames(iFrame5).document
  525.                                                 If ExisteElemento(DocuTemp5, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  526.                                                     _DocActivo = DocuTemp5 : Return True
  527.                                                 End If
  528.  
  529.                                                 'If Docu.frames.length > 0 Then
  530.  
  531.                                                 'End If
  532.  
  533.                                             Next
  534.                                             '*******************************************************>> FRAMES NIVEL5
  535.  
  536.                                         End If
  537.  
  538.                                     Next
  539.                                     '***************************************************************>> FRAMES NIVEL4
  540.  
  541.                                 End If
  542.  
  543.                             Next
  544.                             '***********************************************************************>> FRAMES NIVEL3
  545.                         End If
  546.  
  547.                     Next
  548.                     '********************************************************************************>> FRAMES NIVEL2
  549.                 End If
  550.  
  551.             Next
  552.             '****************************************************************************************>> FRAMES NIVEL1
  553.         End If
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.     End Function
  561.  
  562.     ''' <summary>
  563.     '''
  564.     ''' </summary>
  565.     ''' <param name="oDoc">Documento HTML en el que se busca el Elemento</param>
  566.     ''' <param name="Tipo">Tipo de TAG HTML</param>
  567.     ''' <param name="Id"></param>
  568.     ''' <param name="Nombre"></param>
  569.     ''' <param name="Texto"></param>
  570.     ''' <param name="bTextoExacto"></param>
  571.     ''' <param name="Atributo"></param>
  572.     ''' <param name="ValAtributo"></param>
  573.     ''' <param name="bAtributoExacto"></param>
  574.     ''' <param name="bCol">Si es True Rellena un List con todos los Elementos que coincidan</param>
  575.     ''' <returns></returns>
  576.     ''' <remarks></remarks>
  577.     Public Function ExisteElemento(oDoc As IHTMLDocument3, Tipo As String, _
  578.                                    Optional Id As String = "", _
  579.                                    Optional Nombre As String = "", _
  580.                                    Optional Texto As String = "", _
  581.                                    Optional bTextoExacto As Boolean = True, _
  582.                                    Optional Atributo As String = "", _
  583.                                    Optional ValAtributo As String = "", _
  584.                                    Optional bAtributoExacto As Boolean = True,
  585.                                    Optional bCol As Boolean = False, _
  586.                                    Optional sHTML As String = "", _
  587.                                    Optional bHTMLExacto As Boolean = True) As Boolean
  588.  
  589.  
  590.         Dim NomAtributo As String, ValorAtributo As String
  591.  
  592.  
  593.         ExisteElemento = False
  594.  
  595.         'Doc = DirectCast(oDoc, mshtml.HTMLDocument)
  596.         'Doc = Nothing
  597.  
  598.         If bCol Then _L_oElementos = New List(Of IHTMLElement)
  599.  
  600.         'For Each item In oDoc.getElementsByName(Nombre)
  601.         '    If Nombre <> "" And item.Name = Nombre Then ExisteElemento = True
  602.         '    Debug.Print(item.name)
  603.         'Next
  604.  
  605.         For Each item In oDoc.getElementsByTagName(Tipo)
  606.  
  607.             ExisteElemento = False
  608.  
  609.             'Debug.Print(item.name)
  610.  
  611.             '******** ID
  612.             If Id <> "" Then
  613.                 If bTextoExacto And item.Id = Id Then ExisteElemento = True
  614.                 If Not bTextoExacto And InStr(1, Trim(UCase(item.Id)), Trim(UCase(Id))) > 0 Then ExisteElemento = True
  615.             End If
  616.  
  617.             '******** NOMBRE
  618.             If Nombre <> "" Then
  619.                 If item.Name = Nombre Then ExisteElemento = True
  620.             End If
  621.  
  622.             '******** TEXTO
  623.             If Texto <> "" Then
  624.                 If bTextoExacto And Trim(UCase(item.InnerText)) = Trim(UCase(Texto)) Then
  625.                     ExisteElemento = True
  626.                 End If
  627.                 If Not bTextoExacto And InStr(1, Trim(UCase(item.InnerText)), Trim(UCase(Texto))) > 0 Then
  628.                     ExisteElemento = True
  629.                 End If
  630.             End If
  631.  
  632.             '******** HTML
  633.             Try
  634.                 If sHTML <> "" Then
  635.                     If bHTMLExacto And item.InnerHTML = sHTML Then
  636.                         ExisteElemento = True
  637.                     End If
  638.                     If Not bHTMLExacto And InStr(1, item.InnerHTML, sHTML) > 0 Then
  639.                         ExisteElemento = True
  640.                     End If
  641.                 End If
  642.             Catch ex As Exception
  643.             End Try
  644.  
  645.             '******** ATRIBUTO
  646.             If Atributo <> "" Then
  647.  
  648.                 ValorAtributo = item.getAttribute(Atributo)
  649.  
  650.                 If Not IsNothing(ValorAtributo) Then
  651.  
  652.                     If bAtributoExacto Then
  653.                         If ValorAtributo = ValAtributo Then ExisteElemento = True
  654.                     Else
  655.                         If InStr(1, ValorAtributo, ValAtributo) > 0 Then ExisteElemento = True
  656.                     End If
  657.                 End If
  658.  
  659.                 'For z = 0 To item.attributes.length - 1
  660.  
  661.                 '    NomAtributo = item.attributes(z).name
  662.                 '    ValorAtributo = item.attributes(z).value
  663.  
  664.                 '    If NomAtributo = Atributo Then
  665.  
  666.                 '        If bAtributoExacto Then
  667.                 '            If ValorAtributo = ValAtributo Then ExisteElemento = True
  668.                 '        Else
  669.                 '            If InStr(1, ValorAtributo, ValAtributo) > 0 Then ExisteElemento = True
  670.                 '        End If
  671.  
  672.                 '    End If
  673.  
  674.                 '    'Debug.Print(z & " : " & item.attributes(z).name)
  675.                 '    'Debug.Print(z & " : " & item.attributes(z).value)
  676.                 'Next
  677.  
  678.             End If
  679.  
  680.             If ExisteElemento Then
  681.                 _oElemento = item
  682.                 ' _oElemento2 = item
  683.  
  684.                 '**** EL ELEMENTO ES UN COMBO
  685.                 If Trim(UCase(Tipo)) = "SELECT" Then
  686.                     oCombo = oElemento
  687.                 End If
  688.                 '**** EL ELEMENTO ES UNA TABLA
  689.                 If Trim(UCase(Tipo)) = "TABLE" Then
  690.                     oTabla = oElemento
  691.                 End If
  692.  
  693.                 '*** SI ES COLECCIÓN AÑADIMO ELEMENTO Y CONTINUAMOS BUCLE
  694.                 If bCol Then
  695.                     _L_oElementos.Add(oElemento)
  696.                 Else
  697.                     Exit Function
  698.                 End If
  699.             End If
  700.         Next
  701.  
  702.         If bCol And _L_oElementos.Count > 0 Then ExisteElemento = True
  703.  
  704.     End Function
  705.  
  706.     'Public Function ExisteElemento2(oDoc As IHTMLDocument3, Tipo As String, _
  707.     '                              Optional Id As String = "", _
  708.     '                              Optional Nombre As String = "", _
  709.     '                              Optional Texto As String = "", _
  710.     '                              Optional bTextoExacto As Boolean = True, _
  711.     '                              Optional Atributo As String = "", _
  712.     '                              Optional ValAtributo As String = "", _
  713.     '                              Optional bAtributoExacto As Boolean = True,
  714.     '                              Optional bCol As Boolean = False, _
  715.     '                              Optional sHTML As String = "", _
  716.     '                              Optional bHTMLExacto As Boolean = True) As Boolean
  717.  
  718.     '    ExisteElemento2 = False
  719.  
  720.     '    Dim Docu As IHTMLDocument3
  721.     '    Dim iFrames As Integer
  722.  
  723.  
  724.     '    Doc = DirectCast(oDoc, mshtml.HTMLDocument)
  725.  
  726.  
  727.     '    If Doc.frames.length = 0 Then
  728.  
  729.     '    End If
  730.  
  731.  
  732.     '    For iFrames = 0 To Doc.frames.length
  733.  
  734.     '    Next
  735.  
  736.  
  737.     '    If bCol Then L_oElemento = New List(Of IHTMLElement)
  738.  
  739.     '    'For Each item In oDoc.getElementsByName(Nombre)
  740.     '    '    If Nombre <> "" And item.Name = Nombre Then ExisteElemento2 = True
  741.     '    '    Debug.Print(item.name)
  742.     '    'Next
  743.  
  744.     '    For Each item In oDoc.getElementsByTagName(Tipo)
  745.  
  746.     '        'Debug.Print(item.name)
  747.  
  748.     '        '******** ID
  749.     '        If Id <> "" And item.Id = Id Then ExisteElemento2 = True
  750.  
  751.     '        '******** NOMBRE
  752.     '        If Nombre <> "" And item.Name = Nombre Then
  753.     '            ExisteElemento2 = True
  754.     '        End If
  755.  
  756.     '        '******** TEXTO
  757.     '        If Texto <> "" Then
  758.     '            If bTextoExacto And item.InnerText = Texto Then
  759.     '                ExisteElemento2 = True
  760.     '            End If
  761.     '            If Not bTextoExacto And InStr(1, item.InnerText, Texto) > 0 Then
  762.     '                ExisteElemento2 = True
  763.     '            End If
  764.     '        End If
  765.  
  766.     '        '******** HTML
  767.     '        If sHTML <> "" Then
  768.     '            If bHTMLExacto And item.InnerHTML = sHTML Then
  769.     '                ExisteElemento2 = True
  770.     '            End If
  771.     '            If Not bHTMLExacto And InStr(1, item.InnerHTML, sHTML) > 0 Then
  772.     '                ExisteElemento2 = True
  773.     '            End If
  774.     '        End If
  775.  
  776.     '        '******** ATRIBUTO
  777.     '        If Atributo <> "" Then
  778.  
  779.     '            If Not item.GetAttribute(Atributo) Is Nothing Then
  780.  
  781.     '                If bAtributoExacto Then
  782.     '                    If item.GetAttribute(Atributo) = ValAtributo Then ExisteElemento2 = True
  783.     '                Else
  784.     '                    If InStr(1, item.GetAttribute(Atributo), ValAtributo) > 0 Then ExisteElemento2 = True
  785.     '                End If
  786.  
  787.     '            End If
  788.  
  789.     '            'If bAtributoExacto And item.GetAttribute(Atributo) = ValAtributo Then
  790.     '            '    ExisteElemento2 = True
  791.     '            'End If
  792.     '            'If Not bAtributoExacto And InStr(1, item.GetAttribute(Atributo), ValAtributo) > 0 Then
  793.     '            '    ExisteElemento2 = True
  794.     '            'End If
  795.  
  796.     '        End If
  797.  
  798.     '        If ExisteElemento2 Then
  799.     '            oElemento = item
  800.     '            If Tipo = "SELECT" Then oCombo = oElemento
  801.     '            If bCol Then L_oElemento.Add(oElemento) Else Exit Function
  802.     '        End If
  803.  
  804.     '    Next
  805.  
  806.     '    Doc = Nothing
  807.  
  808.     'End Function
  809.  
  810.     Public Function DameValor(oDoc As IHTMLDocument3, Tipo As String, Nombre As String) As String
  811.  
  812.         DameValor = ""
  813.  
  814.         If Not ExisteElemento(oDoc, Tipo, , Nombre) Then Exit Function
  815.  
  816.         DameValor = oElemento.value
  817.  
  818.     End Function
  819.  
  820.     Public Sub Click(Optional bEsperaCarga As Boolean = True)
  821.         oElemento.click()
  822.         Sleep(_tSleep)
  823.         If bEsperaCarga Then EsperaCarga(4)
  824.     End Sub
  825.  
  826.     Public Sub Valor(sTexto As String, Optional bComboSel As Boolean = False, _
  827.                      Optional bFocus As Boolean = False, _
  828.                      Optional bOnFocus As Boolean = False, _
  829.                      Optional bOnChange As Boolean = False, _
  830.                      Optional bOnBlur As Boolean = False)
  831.  
  832.         On Error GoTo TrataError
  833.  
  834.  
  835.         If bFocus Then oElemento.focus()
  836.         If bOnFocus Then oElemento.onfocus()
  837.  
  838.         oElemento.setAttribute("value", sTexto)
  839.  
  840.         '*** El Elemento es un Combo
  841.         If bComboSel Then
  842.  
  843.             bbComboValor = False
  844.  
  845.             For i As Integer = 0 To oElemento.length - 1
  846.                 If Trim(UCase(oElemento.item(i).text)) = Trim(UCase(sTexto)) Then
  847.                     oElemento.selectedIndex = i : bbComboValor = True : Exit For
  848.                 End If
  849.             Next
  850.         End If
  851.  
  852.         If bOnChange Then oElemento.onchange()
  853.         If bOnBlur Then oElemento.onblur()
  854.  
  855.  
  856.         Exit Sub
  857. TrataError:
  858.  
  859.         _sError = "TABLA_HTML_SQL : Valor() : " & Err.Description
  860.     End Sub
  861.  
  862.     Public Function Combo_Elementos() As Integer
  863.         Combo_Elementos = oCombo.length
  864.     End Function
  865.  
  866.     Public Function Combo_ExisteValor(sValor As String) As Boolean
  867.  
  868.         Combo_ExisteValor = False
  869.  
  870.         For i As Integer = 0 To Combo_Elementos() - 1
  871.  
  872.             Debug.Print(Trim(UCase(oCombo.item(i).text)))
  873.  
  874.             If Trim(UCase(oCombo.item(i).text)) = Trim(UCase(sValor)) Then Combo_ExisteValor = True : Exit Function
  875.         Next
  876.  
  877.  
  878.     End Function
  879.  
  880. #Region "TABLA"
  881.  
  882.     Public Function Tabla_Celda_Valor(Fila As Integer, Columna As Integer) As String
  883.  
  884.         If IsNothing(oTabla.rows(Fila).Cells(Columna).Innertext) Then Return ""
  885.  
  886.         Tabla_Celda_Valor = Trim(oTabla.rows(Fila).Cells(Columna).Innertext.ToString)
  887.  
  888.     End Function
  889.  
  890.     Public Function Tabla_Filas() As Integer
  891.         Tabla_Filas = oTabla.rows.length
  892.     End Function
  893.  
  894.     Public Function Tabla_Columnas(Fila As Integer) As Integer
  895.         Tabla_Columnas = oTabla.rows(Fila).cells.length
  896.     End Function
  897.  
  898. #End Region
  899.  
  900. #End Region
  901.  
  902. #Region "MÉTODOS PRIVADOS"
  903.  
  904.     Private Sub CargaVariables()
  905.  
  906.         _tSleep = 2000
  907.  
  908.         '_bNaviScriptError = True
  909.         'oNavegador.ScriptErrorsSuppressed = _bNaviScriptError
  910.  
  911.     End Sub
  912.  
  913. #End Region
  914.  
  915.  
  916. End Class
Advertisement
Add Comment
Please, Sign In to add comment