Question selecting combobox on webbrowser control

knowmeifyou

Active member
Joined
Jun 16, 2013
Messages
26
Programming Experience
Beginner
here is the website
VB.NET:
http://www.afreesms.com/freesms
here is my codes
VB.NET:
using vb.net and webbrowser control
wb name of my webbrowser control
to select item on combobox and its working
VB.NET:
Try
                Dim element As HtmlElement = wb.Document.GetElementById("countrycode")
                Dim month As HtmlElement = element.GetElementsByTagName("option").Cast(Of HtmlElement).First(Function(el) el.GetAttribute("value") = "PH")
                month.SetAttribute("selected", "true")
            Catch ex As Exception
                MsgBox(ex.StackTrace)
            End Try


here is the output


1.png


but using a webbrowser installed on pc i get this result

2.png

the problem is when using my program. it doesnt hide the
VB.NET:
sender id: country code: and mobile number


and it doesnt add the country code + 63 below the combo box after choosing the country


any idea guys? what additional codes i need to add on my codes
 
What you have posted is pretty vague. It doesn't even bother trying to manipulate the objects in question. Also, we don't have any clue as to what the HTML looks like in the background.

In your code, try to find the rest of the elements in the same way you did the combobox ... GetElementsByTagName

Then set the various properties you want to manipulate. (Visible, Text, Etc.)
 
vague (unclear)?
what i mean sir. the program im doing is not doing the task i want to do. and when im using a web browser like chrome it gives me the necessary output.

i dont need to hide some of the textbox sir because after selecting my country it hides the textbox and gives me the country code (if using a web browser)

sorry for my bad english
 
Yes, unclear. You have not provided enough code to determine what the problem might be. However, I think your problem may be related to javascript, xajax, and your mobile browser.
 
I think I understand what you are trying to do.

Problem:
There is a website that you want to display in your application using a webbrowser control. However, the website does not display correctly in the control.
You are trying to manipulate the website through your application logic and it does not operate as it does in Chrome, Internet Explorer, Firefox or other webbrowser.

Why this does not work:
The website you are trying to manipulate through your application code makes use of a javascipt application called xajax. The problem is that the events that set the visibility of the controls use javascript to create a postback and the items are then hidden by the code on the server before the new page is rendered to the webbrowser. When you change the selected item in the combobox from your code, the javascript client event for onchange does not fire. The result is that xajax never posts back to the server thereby rendering the page as you would like. You have inadvertently broken the functionality of the page.


How to attempt to fix the issue:
Call the onchange event from your code (I have not tested this code so I cannot guarantee it works)
VB.NET:
HtmlElement.InvokeMember("OnChange")

OR

Determine if the server will accept url encoded parameters to set the value of the combobox. This will take some considerable investigation into the postback functions of the xajax application or by lots of trial and error.

OR

Call the xajax function directly passing the parameters as needed. You will still need to investigate the xajax functions to be able to do this.

OR

Use the same logic that you applied to set the combobox value to the style of the controls you would like to hide and then hide those by setting the the style to display:none they will not show. Also, if you want to change the text of the + beside the textbox, you can do that as well ... however, without knowing how the server side code parses the final submit from the button, you may also have broken something else.


Because you apparently don't have access to the server code, doing this will probably take alot more investigation into resolving the issue, also keep in mind that when the website you are accessing changes, it may break your application.
 
What have you tried? I can't help you without knowing what you are doing. I don't have any code to look at.

If it is not working as expected, perhaps the page is not loading completely before you invoke the click event. Try invoking the click event after the webbrowser control has loaded by placing the code inside the event handler DocumentCompleted.
 
btw is there any way that i can get the combobox items and put it to my program?

just like passing the values from the website to my vb.net program?
 
I don't think you want to raise the submit event. Try raising the OnClick event for the submit button in the form instead.

Also, to get the value of the combobox, just as you have used the code in your first post, you can get the value of the control, and that should be the text you are looking for.
 
Back
Top