Results 1 to 5 of 5

Thread: How to click select component in a Web page using HTML DOM

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    How to click select component in a Web page using HTML DOM

    Hi all,

    Is there any idea to click the select component of an HTML page programitically

    Here is the HTMT code

    HTML Code:
    <td width="83%" align=left nowrap><font face="Times New Roman, Times, serif"> 
    			<select name=cboPrimary size=1 onChange="RemoveOptionAndSubmit(cboSecondary)" style="width=350px;">
    <option value="003"  >ALLIED BANKING CORPORATION - $ BTB (USD  )</option> 
    <option value="004"  >ALLIED BANKING CORPORATION - PESO BTB (PHP  )</option> 
    <option value="008"  >ALLIED BANKING CORPORATION - PESO DTOD (PHP  )</option> 
    <option value="052"  >BANK OF THE PHILIPPINE ISLAND (USD  )</option> 
    <option value="049"  >BANK OF THE PHILLIPINE ISLAND (PHP  )</option> 
    <option value="179"  >EQUITABLE BANK / PCI (PHP  )</option> 
    <option value="175"  >METRO BANK (PHP  )</option> 
    <option value="176"  >METRO BANK - $ (USD  )</option> 
    <option value="177"  >PHILIPPINE NATIONAL BANK (PHP  )</option> 
    <option value="178"  >PHILIPPINE NATIONAL BANK - $ (USD  )</option> 
              	</select>
              	</font>
    		 </td>
    When one of bank is selected, the branches of that bank will be lsited.

    Now I want to do this process programtically.

    Here I used this code:

    VB Code:
    1. Dim BankIndex as Integer
    2. Dim BankName as String
    3. BankIndex  =  5
    4. browser.Document.getElementById("cboPrimary").selectedIndex = BankIndex

    This code select the expected bank BANK OF THE PHILIPPINE ISLAND (USD )

    But the page not lists the branch of this bank. It still remain wihout any action.

    I also tried with the following code

    VB Code:
    1. browser.Document.getElementById("cboPrimary").click

    But no effect

    Is there any suggession to solve this problem

    With regards,
    Nasreen
    Last edited by nasreen; Feb 12th, 2007 at 12:54 PM. Reason: Spell corret

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How to click select component in a Web page using HTML DOM

    Use the HTMLObject Library
    try this.. let me know
    VB Code:
    1. Dim HTML As HTMLDocument
    2.     Dim INP As HTMLSelectElement
    3.     Set HTML = webbrowser1.document
    4.     For Each INP In HTML.getElementsByTagName("select")
    5.         If INP.Name = "cboPrimary" Then
    6.             INP.Value = "052"
    7.             Exit For
    8.         End If
    9.     Next
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: How to click select component in a Web page using HTML DOM

    Thanks
    The code is working same as the code I quoted before. Nothing more.
    However I have got the idea to get the expected result by adding the following code also

    VB Code:
    1. browser.Document.getElementById("cboPrimary").onchange

    This will trigger the click event for the select component.

    With regards,
    Nasreen

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to click select component in a Web page using HTML DOM

    So, is the problem resolved?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: How to click select component in a Web page using HTML DOM

    Hi All,

    How we can programitically click a button or link of a web page viewed in FRAMED web page.

    I use for a web page without frame the following code :

    VB Code:
    1. Dim WithEvents objDocument As HTMLDocument
    2.  
    3. Private Sub browser_DownloadComplete()
    4. Set objDocument = browser.Document
    5. End Sub

    This code work fine and without error.

    But I want to do the same function in a web page with three frames, to control the mouse click programitically.

    I used the the following code

    VB Code:
    1. Dim WithEvents objFrame As HTMLDocument
    2.  
    3. Private Sub browser_DownloadComplete()
    4. Set objFrame = browser.Document.frames(0).Document.Frame
    5. End Sub

    But when execute the line (Set objFrame = browser.Document.frames(0).Document.Frame)

    I got a runtime error saying Exception occurred.

    I also changed that line as :
    VB Code:
    1. Set objFrame = browser.Document.frames.Item(2).Document

    But I get another error saying Object or class does not support the set of events

    Any idea to solve this problem or any idea to control the mouse click in a framed web page

    With regards,
    Nasreen
    Last edited by nasreen; Mar 4th, 2007 at 08:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width