郑小铁吧 关注:364贴子:6,913
  • 5回复贴,共1

我来接找元素方法

只看楼主收藏回复

http://tieba.baidu.com/p/4016293062
找之前先创建IE


IP属地:浙江1楼2015-09-09 09:56回复
    以百度为例,打开IE到百度,按f12键找到DOM


    IP属地:浙江2楼2015-09-09 10:08
    回复
      找到搜索框代码
      <input name="wd" class="s_ipt" id="kw" maxlength="255" value="" autocomplete="off">


      IP属地:浙江3楼2015-09-09 10:12
      回复
        '‘VBA语法
        '通过id找到dom元素
        Set 操作ie = ie.Document.getElementById("kw")
        '显示找到的元素看对不对
        Debug.Print 操作ie.outerhtml


        IP属地:浙江4楼2015-09-09 10:22
        回复
          '按键语法
          '通过id找到dom元素
          Set 操作ie = ie.Document.getElementById("kw")
          '显示找到的元素看对不对
          TracePrint 操作ie.outerhtml


          IP属地:浙江5楼2015-09-09 12:34
          回复
            '‘VBA语法
            '通过名称找dom元素组合,并把元素组合赋给操作ie
            Set 操作ie = ie.Document.getElementsByName("wd")
            'Debug.Print 操作ie
            个数 = 10
            For 序号 = 0 To 个数
            Set 操作ie1 = 操作ie(序号)
            If 操作ie1.ID = "kw" Then
            Debug.Print "找到了"
            '查看id
            Debug.Print 操作ie1.ID
            '查看name
            Debug.Print 操作ie1.Name
            '查看type
            Debug.Print 操作ie1.Type
            '查看标签
            Debug.Print 操作ie1.TagName
            '查看类名
            Debug.Print 操作ie1.className
            Debug.Print "序号 =" & 序号
            Exit For
            ElseIf 序号 = 个数 Then
            序号 = 0
            个数 = 个数 * 10
            End If
            If 操作ie(序号) = Empty Then
            Debug.Print "找不到请检查程序"
            Exit For
            End If
            '显示找到的元素看对不对
            Next
            '查看元素
            Debug.Print 操作ie1.outerhtml
            Set 操作ie = 操作ie1
            '覆盖操作ie
            Debug.Print 操作ie.outerhtml


            IP属地:浙江7楼2015-09-09 13:50
            回复