|
-
Oct 6th, 2010, 05:22 AM
#1
Thread Starter
New Member
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.
-
Oct 6th, 2010, 10:50 AM
#2
Re: How can I right click on HTML HTML Element?
 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 ?
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,...
-
Oct 6th, 2010, 11:14 PM
#3
Thread Starter
New Member
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.
-
Oct 7th, 2010, 01:00 AM
#4
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.
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
-
Oct 7th, 2010, 06:49 AM
#5
Thread Starter
New Member
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...?
-
Oct 7th, 2010, 10:06 AM
#6
Re: How can I right click on HTML HTML Element?
 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 ?
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,...
-
Oct 7th, 2010, 10:19 AM
#7
Thread Starter
New Member
Re: How can I right click on HTML HTML Element?
 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.
-
Oct 8th, 2010, 06:36 AM
#8
Thread Starter
New Member
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.
-
Oct 9th, 2010, 06:05 AM
#9
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
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
-
Oct 29th, 2010, 12:28 AM
#10
Thread Starter
New Member
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.
-
Oct 29th, 2010, 03:46 AM
#11
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
-
Oct 29th, 2010, 05:09 AM
#12
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|