Get href of a button through web browser control - vb.net

I'm trying to get the href of a button using the control Web Browser.
The html is:
<a download="" href="https://x638jxfnvmcxbaxcskqsdadskdqnfwexc.shikisha.shiksha/f2xcqrz1wxf13dssdalkgrdjkgdklfjdsaklkcxmsacxzcdfsvsdcqwdjkkvfmdskicmsdascmamzcassmdamcxscxzcsacasvfdssacxzcsdxvsaqswcxzvbededvvb.php?nqusjmslpeprtmdsjkhghewojicwe0guhifkjbh2qqqhstexrsfiwhvfmmoorewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdwxjwsfiwhvfhlmj=yyhnlsoahifiztdsjkhghewojicwe0guhifkjbh2qqqhscscvsfiwhvffbbsrewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdryansfiwhvfmwdn222811prciwnbztwy5&pxhotisnweqwlkdsjkhghewojicwe0guhifkjbh2qqqhsotjpsfiwhvfnshnrewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdnpsesfiwhvfoczq=yloyeevwdfcbpkdsjkhghewojicwe0guhifkjbh2qqqhszjdssfiwhvfeyczrewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdozixsfiwhvfhcimfslzpcikfrvnqldsjkhghewojicwe0guhifkjbh2qqqhsptjesfiwhvfmzsrrewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdyskesfiwhvfcchh&fkdsadxcwaqcscasxcsacxsaxazxcvsdvdslssafdsvx=174147325&dkjfsjksdadsdvcxxcvswscxrewsdf=sdx2&sdwreggllslsdxvc&sadklxcklkvb=qwrdcbkklsdxk&jiijlks=lz9fSJUhlRoBL8M8qh4Ido&uijdsdkdfkgfdsd=85652262237b1335ca34.14415852&lkfdsfxc=lz9fSJUhlRoBL8M8qh4Ido&nqusjmslpeprtmdsjkhghewojicwe0guhifkjbh2qqqhstexrsfiwhvfmmoorewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdwxjwsfiwhvfhlmj=yyhnlsoahifiztdsjkhghewojicwe0guhifkjbh2qqqhscscvsfiwhvffbbsrewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdryansfiwhvfmwdn222811prciwnbztwy5&pxhotisnweqwlkdsjkhghewojicwe0guhifkjbh2qqqhsotjpsfiwhvfnshnrewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdnpsesfiwhvfoczq=yloyeevwdfcbpkdsjkhghewojicwe0guhifkjbh2qqqhszjdssfiwhvfeyczrewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdozixsfiwhvfhcimfslzpcikfrvnqldsjkhghewojicwe0guhifkjbh2qqqhsptjesfiwhvfmzsrrewioujgbhuiovshdkjwvcjhfdbwehjkvkjhsdnvmwouipfdyskesfiwhvfcchh"><button id="myImageId44" type="button" class="download2 download2dahover"><font color="#F08080">Download MP3 (Bitrate: 320 kbps | 7.28 MB | 00:03:10)</font></button></a>
The code I'm trying inside the event Document Completed of the Web Browser control is:
Dim HtmlCollec As HtmlElementCollection
HtmlCollec = WebBrowser1.Document.GetElementsByTagName("button")
For Each iElement As HtmlElement In HtmlCollec
If iElement.GetAttribute("id").Equals("myImageId44") Then
RichTextBox1.Text = iElement.ToString
End If
Next
but Im getting as output:
System.Windows.Forms.HtmlElement
How can I get it? Thanks

Related

How to click Image button in website vb.net

so i am trying to click a image button in website with HTML code:
<a onclick="trylogin()"><img class="loginButton" src="/student/resource/AWSEd_Resource/img/search-execute.png"></a>
i've tried:
Dim element As HtmlElement = (From el As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a").Cast(Of HtmlElement).Where(Function(h) h.GetAttribute("onclick") = "trylogin()")).FirstOrDefault()
element.InvokeMember("click")
And:
WebBrowser1.Document.Forms(0).InvokeMember("loginButton")
This is image button
Try executing the script directly using HtmlDocument.InvokeScript():
WebBrowser1.Document.InvokeScript("trylogin")

Simulate Click event on a DIV element

I cannot simulate a click event on a div element. The HTML code is this one:
<div id="export" data-export="true" data-timespan="">
<button class="btn btn-default ladda-button" type="button" data-style="expand-right" data-spinner-color="#8899a6">
<span class="Icon Icon--featherDownload"></span>
<span class="ladda-label">
Exportar datos
</span>
<span class="ladda-spinner"></span></button>
<div class="hidden error server Callout Callout--danger">
<p>Ocurrió un problema al exportar tus datos, inténtalo de nuevo más tarde.</p>
</div>
</div>
In the webpage, is just a button that downloads a file when clicked. There is no URL. But after checking the code, is the div element what triggers the click event. Look the image.
Click to see image
That "g.handle" triggers a js.file form the website.
My vba code works perfect for doing other stuff in the website, but I cannot accomplish this task.
I've tried all this options:
Set div = HTMLDoc.getElementById("export")
div.FireEvent ("onclick")
div.Click
HTMLDoc.all.Item
Call HTMLDoc.parentWindow.execScript("g.handle", "JavaScript")
Nothing works. I'm kind of blocked right now and I have no idea of how to proceed. Maybe this has no solution? I have almost no idea of HTML and I have 0 idea of Javascript. But it must have a solution, because if I do it manually, i click on that DIV, wait some seconds and download my file.
Thanks in advance. Any help is welcome.
You didn't specify if the highlighted portion was the html code for the button or not, but it appears from looking at it that it isn't.
You can grab the class name for your button. The name may or may not be unique, and it's difficult to know that without seeing the entire html code, but you can set the btn variable below to the first instance of that class name. If there are multiple class names in your html code, then you will need to use a For Each...Next statement to iterate through them (unless you know the instance number off hand).
So we will go with the first instance of your class, hence the reason for the (0) appended on the end.
Sub Test()
Dim ie As New InternetExplorer, HTMLDoc As HTMLDocument, btn As Object
ie.navigate Url 'whatever this may be
' Some code to wait for your page to fully load
Set HTMLDoc = ie.document
Set btn = HTMLDoc.getElementsByClassName("btn btn-default ladda-button")(0)
btn.Click
End Sub

IFRAME with HTA prompt with VB

I have an HTA prompt with VB code. I would like a URL loaded within the HTA window when the "SUBMIT" button is clicked. However, I cannot find any information that is helpful for my situation. Can someone please help me include an iframe in my HTA prompt so that a website can be displayed? I can use https://www.google.com as an example. Let me know if you have any questions.
Here is the code I currently have for the submit button:
bodystring = bodystring & "<BR><BR><BUTTON CLASS='Bttn_Back' OnClick='PrevStage()'>BACK</BUTTON> <BUTTON CLASS='Bttn_Submit' OnClick='NextStage()'>SUBMIT SURVEY</BUTTON>"
Here is my section of code for the "NextStage()" function:
ElseIf STAGE = 62 Then
SaveResults()
Window.Close()
End If
Put this to the HTML of the HTA:
<iframe id="htmlhere" src="" style="display: none;"></iframe>
Then in nextStage():
document.getElementById("htmlhere").src = "http:/..."; // Loads a new document to iframe
document.getElementById("htmlhere").style.display = ""; // Setting style.display empty shows the iframe
Sorry for using JS, but my VB skills are more or less zero.

Clicking HTML button in vb.net

I have to click a HTML button programatically which is on the 3rd page of the website . The button is without id. It has just name type and value . The HTML code of the button is given below
<FORM NAME='form1' METHOD='post' action='/dflogin.php'><INPUT TYPE='hidden' NAME='txtId' value='E712050-15'><INPUT TYPE='hidden' NAME='txtassId' value='1'><INPUT TYPE='hidden' NAME='txtPsw' value='HH29'><INPUT TYPE='hidden' NAME='txtLog' value='0'><h6 align='right'><INPUT TYPE='SUBMIT' NAME='btnSub' value='Next' style='background-color:#009900; color:#fff;'></h6></FORM>
i am using the following code to click it
For Each webpageelement As HtmlElement In allButtons
If webpageelement.GetAttribute("value") = "Next" Then
webpageelement.InvokeMember("click")
End If
Next
But i cant able to click it . I am using the vb.net 2008 platform. Can anyone tell me the solution to click it?
I was having the same problem as you. The InvokeMember looks correct so I can only assume its not picking up the correct html element. Try refering to the element explicitly using the value. The following code worked for me but I have adapted it for you:
For Each webpageelement As HtmlElement In allButtons
If webpageelement.GetAttribute("value").Equals("E712050-15") Then
webpageelement.InvokeMember("click")
Exit For
End If
Next
Good Luck :)

IE automation send the HTTP Post directly to the form action using VBA

I am having some automation trouble.
I am using HTML Object Library to automate an download. At the end of the automation process, I have to click a submit button of a form and then the download starts.
When I try to handle the dialog with the winapi32 function like this:
hWndDialog = 0
'Wait until the dialog is open
While hWndDialog = 0
hWndDialog = FindWindow(vbNullString, "Dateidownload")
Wend
'get the handle of the button
hWndDialogSpeichern = FindWindowEx(hWndDialog, 0, "Button", "&Speichern")
Call SetForegroundWindow(hWndDialog)
'send message
lRetval = SendMessage(hWndDialogSpeichern, &H5, ByVal 0&, ByVal 0&)
Nothing happens. I read something, that this isn't possible, because the dialog is modal?
So I try to send the POST data directly to the form's action. I think this is the best possibility even.
But I don't know what to send to the server.
Here the form in the html page:
<form action="/smarti/bismt/bismt/resexport" method="post">
<input class="active" type="button" onclick="submitform()" name="button_export" value="Export">
submitform() only check some values and then calls:
document.forms[0].submit();
However, when I send a POST request to "/smarti/bismt/bismt/resexport" I only get the page. I don't know how to set up the request header. Tried to use firebug, to see what is sending to the form, but saw nothing I recognized.
Did you try adding a question mark ? and then the names of the text input boxes? Like http://zip4.usps.com/zip4/zcl_3_results.jsp?zip5=92101.