Results 1 to 12 of 12

Thread: How can I right click on HTML HTML Element?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    How can I right click on HTML HTML Element?

    Hi,

    I am facing one issue with HTML programming with VB 6.0. I have created one automate program to fill a web form on the internet with Visual Basic 6.0. For example observer below code.

    Step 1: Create one Standard EXE project.

    Step 2: Add reference to "Microsoft HTML Object Library" - You can add this from \windows\system32\mshtml.tlb

    Step 3: Add reference to "Microsoft Internet Controls" - You can add this from \windows\system32\ieframe.dll.

    Copy and Paste Below code in form1.

    Code:
    Private Sub Form_Load()
    
    Dim IE As SHDocVw.InternetExplorer
    Set IE = Nothing
    Set IE = CreateObject("InternetExplorer.Application")
    
    IE.Navigate "www.google.com"
    
    Do While IE.Busy
        DoEvents
        DoEvents
    Loop
    
    IE.Visible = True
    
    Dim HtmEle As HTMLHtmlElement
    DoEvents
    DoEvents
    IE.Document.getElementById("q").Value = "text"
    DoEvents
    DoEvents
    
    Set HtmEle = IE.Document.getElementById("btng")
    If Not HtmEle Is Nothing Then
        MsgBox "HtmEle Object set." & vbCrLf & "Now it will click on Google Search button."
        HtmEle.Click
    End If
    
    End
    
    End Sub
    Now instead of doing this click on Google Search button I want to do Right Click on that button. I tried to do it with mouse_event API it would solve my issue. But it gets failed when I resize the IE or move IE. I think I will require X,Y co-ordinate of that htmele.

    Is there any way from that I can do right click on that htmele?
    If I can get X,Y co-ordinate of htmEle in screen that would be also very helpful.

    Thanks in advance.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: How can I right click on HTML HTML Element?

    Quote Originally Posted by snkt_shah View Post
    Now instead of doing this click on Google Search button I want to do Right Click on that button.
    Why you want to right click ?

    Could you tell us the reason ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    Re: How can I right click on HTML HTML Element?

    Yes, sure. I can tell you the reason.
    Actually my one customer having its internal site. On one page of that site one table is designed and if we do the right click on any of the row of that table will open an pop up menu. I want to select one item of that menu. I am able to click on that pop up menu item but before that I would have to open that pop up menu and to open that menu I will have to perform right click on that table row.
    My current code can set the TD element of that tabe as an HTMLHTMLElement

    Hope, this would be helpful.

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: How can I right click on HTML HTML Element?

    You could try something like:
    vb Code:
    1. 'Must Add Microsoft HTML Object Library
    2. Option Explicit
    3.     Public WithEvents HTML As HTMLDocument
    4.  
    5. Private Function HTML_oncontextmenu() As Boolean
    6.    HTML_oncontextmenu = False
    7.    PopupMenu mnu '<---Check the mnu to your own menu name
    8. End Function
    9.  
    10. Private Sub Form_Load()
    11.     WebBrowser1.Navigate "www.google.com"
    12. End Sub
    13.  
    14. Private Sub Form_Unload(Cancel As Integer)
    15.    Set HTML = Nothing
    16. End Sub
    17.  
    18. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
    19.                                                  URL As Variant)
    20.    Set HTML = WebBrowser1.Document
    21. End Sub

    That example is the last one on this page.

    Edit:

    Since, pop up operates on a right click you have the code to click the button in the menu and set the menu visibility option to false that way users wont realize it is menu you are using to call the function.
    Last edited by Nightwalker83; Oct 7th, 2010 at 01:10 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    Re: How can I right click on HTML HTML Element?

    Hi,
    Thanks for your reply.

    Actually as I mentioned that site is my customer's internal site. I don't want to display my pop up menu on that page while right click on that. Actually the site is designed in such a way that when we right click on that table row it will open an pop up menu. Which is designed by the site developer.

    I think anyhow if we can get the x,y co-ordinate of that TD on screen would be helpful. From that we can easily able to fire right click on that TD tag by mouse_event API.

    Any suggestion...?

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: How can I right click on HTML HTML Element?

    Quote Originally Posted by snkt_shah View Post
    Hi,
    Thanks for your reply.

    Actually as I mentioned that site is my customer's internal site. I don't want to display my pop up menu on that page while right click on that. Actually the site is designed in such a way that when we right click on that table row it will open an pop up menu. Which is designed by the site developer.

    I think anyhow if we can get the x,y co-ordinate of that TD on screen would be helpful. From that we can easily able to fire right click on that TD tag by mouse_event API.

    Any suggestion...?
    There might be some other way to do that. Do you have the source code of that page ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    Re: How can I right click on HTML HTML Element?

    Quote Originally Posted by akhileshbc View Post
    There might be some other way to do that. Do you have the source code of that page ?
    Hi,
    As I already mentioned that Its customer https secured site. So I couldn't get that page source.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    Re: How can I right click on HTML HTML Element?

    I could not got the source from client but I found one page with the same menu.

    http://www.harelmalka.com/rightcontext/?trigger=RIGHT

    you will find a pop up menu when you will right click on "Anchor tag test. Right click me." link on page.

    I am easily able to perform click on that "The second item in the menu. Will only show if cond eq Y (it is Y)" But to on this menu item I have to open an Pop Up by right clicking on that page which want to possible without X,Y co-ordinate.

    Can you please help me out?

    Hope, this would be very helpful for you.

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How can I right click on HTML HTML Element?

    you can see if this can help get the top position of an element, do the same for left
    vb Code:
    1. For Each ele In wb.Document.getElementsByTagName("span")
    2.     If ele.innerText = "Harel Malka" Then Stop
    3.     Set par = ele
    4. '    mytop = par.offsetTop
    5.     Do
    6.         mytop = mytop + par.offsetTop
    7.         Set par = par.parentElement
    8.     Loop While Not par Is Nothing
    9.    
    10. Next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    Re: How can I right click on HTML HTML Element?

    Hi,

    I tried with this code but it couldn't help me out. While I did googled I found that there is something attachevent and detachevent is there to perform right click for htmldocument. Hope we can do that with HtmlElement also. But I don't know how to do that.

    I found one link for Right Click


    I don't know that how to do that.

    Can anybody give me some solution?

    Thanks.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How can I right click on HTML HTML Element?

    that looks like the opposite of what you want to do

    that is to create some event when right click happens by mouse
    you just want to show the default menu without clicking mouse?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    15

    Arrow Re: How can I right click on HTML HTML Element?

    Hi,

    Thanks for your reply.

    Let me explain,

    right now if we want to click on "Anchor tag test. Right click me. " link, we will do the following,

    Private Sub Command4_Click()
    Dim HtmEle As HTMLHtmlElement
    Set HtmEle = Htmdoc.getElementById("link")
    HtmEle.click '' We can also call -- HtmEle.fireevent "click"
    End sub

    Just like this, What if I want to do Rightclick on that menu?
    It should open directly, without use of mouse.

    I tried the same thing by using,
    Htmdoc.CreateEventobject and htmele.attachevent and htmele.detachevent.
    But it couldn't help me.

    and,
    htmele.attachevent
    htmele.detachevent

Tags for this Thread

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