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.
Re: How can I right click on HTML HTML Element?
Quote:
Originally Posted by
snkt_shah
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 ?:confused:
Could you tell us the reason ?
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.
Re: How can I right click on HTML HTML Element?
You could try something like:
vb Code:
'Must Add Microsoft HTML Object Library
Option Explicit
Public WithEvents HTML As HTMLDocument
Private Function HTML_oncontextmenu() As Boolean
HTML_oncontextmenu = False
PopupMenu mnu '<---Check the mnu to your own menu name
End Function
Private Sub Form_Load()
WebBrowser1.Navigate "www.google.com"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set HTML = Nothing
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
URL As Variant)
Set HTML = WebBrowser1.Document
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.
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...?
Re: How can I right click on HTML HTML Element?
Quote:
Originally Posted by
snkt_shah
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 ?
Re: How can I right click on HTML HTML Element?
Quote:
Originally Posted by
akhileshbc
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.
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.
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:
For Each ele In wb.Document.getElementsByTagName("span")
If ele.innerText = "Harel Malka" Then Stop
Set par = ele
' mytop = par.offsetTop
Do
mytop = mytop + par.offsetTop
Set par = par.parentElement
Loop While Not par Is Nothing
Next
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.
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?
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