How to set value of a editable combo box in an InternetExplorer window using VBScript? - vb.net

can anyone please tell me how to set the value of a editable combobox in an IE window using vbscript?
I have set the IE window that i want to use, as an object.
If it was a text box, i have used
ie.document.all("textboxname").value = "textboxvalue"
For radiobutton, i have used
ie.document.all("radiobuttonname")(2).click --- where '2' is index of array (3rd value in array is selected)
For noneditable combobox, i have used
ie.document.all("comboboxname").selectedindex = 2 --- where '2' is index of array
All the above codes work fine, but I am not able to set value for the editable comboboxes in that IE window.
For editable combobox, i tried
ie.document.all("editablecomboboxname").selectedindex = 2
or
ie.document.all("editablecomboboxname").selectedindex.text = "text of any options in the combobox"
or
ie.document.all("editablecomboboxname").selectedindex(2).click
or
ie.document.all("editablecomboboxname").options.selected = 2
But everything leads to this error - "Object doesn't support this property or method: "
Can anyone help me with this? Thanks in advance
Please note I am using only VBscript and no other tools like Visual Studio or QTP.
As per Panayot Karabakalov asked, I have added an example of the code for one such editable combo box below :
<td class="small">
<span id="Curr Car Name" style = "display:none;" class = "small">
Curr Car Name
<font class="asteriskRed" style="font-size:11px" style="display:none;">*</font><br>
<input type="hidden" name='curr_car_name' id='curr_car_name' value='' style='width:180px;height=20px;' >
<script>
getTypeAhead(true,true,'curr_car_name',180,20,'null','AutoCompleteHighlight', 'AutoCompleteBackground','divclass','null',5,20,'curr_car_name_datasrc','','null',0,'setHHChangeIndicator();priorValidations();deleteRowFromAccordion(this);',310,100,'null','');
searchandFill('curr_car_name','',curr_car_name_datasrc);</script>
</span>
<input type="hidden" name="currentcarriernameHdd" id="currentcarriernameHdd" value="null"/>
</td
I saved the webpage(created in Java) as html file and viewed its source code. From there, I have copied and pasted the code for the combobox above. I am not sure if it will be helpful, as I dont have much knowledge of Java.
-- Deepak.

Well, I'll post what I have in mind.
Looking to the error description (Object doesn't support this property or method),
seems to me that your call-by-name...
ie.document.all("editablecomboboxname")
...return different object, i.e. not the element you expected. And as you have not
access to the plain HTML source code, that complicate debuging.
I suspect a naming conflict. What you can do is to see what returns your call-by-name.
MsgBox TypeName(ie.document.all("editablecomboboxname").Type)
But if there some naming conflict, I don't know how you can debug it without
the actual corresponding HTML code block.

# Panayot - Got the answer to my question!!
As you said, I tried with
MsgBox TypeName(ie.document.all("editablecomboboxname").Type)
It returned "String". So I went to a Java colleague of mine and asked him why the combobox is not getting updated even though inputtype is string. After a lot of discussion, he gave me two fields to update for the combobox - a label field to be updated with the string that I wanted in the combobox and another field to be updated with the value corresponding to the string I selected. This is what I used :
ie.document.all("curr_car_name").value = 8001
ie.document.all("_lblcurr_car_name").value = "NO PRIOR CARRIER"
The "curr_car_name" is the editable combobox name, and the "_lblcurr_car_name" is the label for the editable combobox. "NO PRIOR CARRIER" is the text that I wanted the combobox to have, and 8001 is its corresponding value. I got the value 8001 from the javascript that the webpage contained.
This works. :)
Thank you Panayot for all the help.

Related

Selenium driver with VBA - select option in <input drop down

I read all the relevant threads in the forum, to no avail. I try to select an option in a dropdown in this hTML code:
<input name="tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails" type="text" id="tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails" class="async_list" autocomplete="off" data-ajax-id="CustomFieldLookup" data-ajax-allow-query="True" data-ajax-param1="143" data-ajax-param2="" data-selected-value="Pending">
So far, I am able to extract the current value with either options:
driver.FindElementByName("tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails").value
driver.FindElementByXPath("//*[#name='tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails']").Attribute("data-selected-value")
For the input, I tried the following methods:
driver.FindElementByXPath("//*[#name='tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails']").AsSelect.SelectByValue "Completed"
'That returns the error: "Unexpected TagName Error. Expected=select Got=input"
driver.FindElementByXPath("//*[#name='tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails']").SendKeys "Completed"
'This writes the value in the dropdown but it cannot be saved
Any idea?
Many thanks in advance.
If sendkeys is working perhaps you may need to select the option from the dropdown in addition to typing it. I have run into scenarios where you need to select the option from the drop down after you have sent it. In a side note: I have noticed that having waits between inputs also helps.
Example
driver.FindElementByXPath("//*[#name='tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails']").SendKeys "Completed"
driver.Wait (10)
driver.SendKeys keys.ArrowDown
driver.SendKeys keys.Enter
I have noticed that in some lists, you need to add a wild card in the send keys method to correctly retrieve the option and then do the selection.

Why the field in webbrowser is still consider as empty even I already set its value?

enter image description hereI'm trying to automate our ticketing system using visual basic. However, I can't save the profile because the field in webbrowser is still read as empty even I already set its value:
I also tried to set the attribute originalvalue, prekeyvalue etc. but still not working. But if you manual type the value in the field, it will work.
My code below:
WebBrowser1.Document.GetElementById("mb8a86d99-tb").SetAttribute("value", "EMAIL")
The information of field below:
<input datatype="0" id="mb8a86d99-tb" aria-required="true" role="textbox" aria-labelledby="mb8a86d99-lb" class="fld text fld fld_req" ctype="textbox" li="mb8a86d99-img" maxlength="512" style=";width:225.0px;" async="1" ae="setvalue" type="text" value="" ov="" work="1" fldinfo="{"lookup":"valuelist","dsid":"TSDTKTSOURCE","inttype":"0","afindex":"0","length":"512","required":true}" title="" originalvalue="" prekeyvalue="" stoptcclick="true">
This kind of problem seems to occur in some web pages when the form containing your input does not get activated (it's a form of protection on client-side made to avoid the insertion of values programmatically).
If you manually type the value in it, the form turns active because you're clicking on the input which is a child of the form. However, if you do it programmatically, the activation is not triggered and so the value that you add to the HTML is not taken by the client.
You can try to emulate the activation of the form with the Focus method on your input:
WebBrowser1.Document.GetElementById("mb8a86d99-tb").Focus
WebBrowser1.Document.GetElementById("mb8a86d99-tb").SetAttribute("value", "EMAIL")
If that still doesn't work, try to add a Application.Wait(TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 2)) between one command and the other to let the form the time to actually activate itself.

Tick Checkbox on Webpage using VBA

I am trying to automate one webpage based activity, where I need to select the Checkbox. There are multiple Checkbox available on the page and out of those, I need to select a particular one. I have tried many solutions provided on internet, but it gives me only one error as "object doesn't support this property or method". Below is the HTML code for the Checkbox. It would be really helpful if you revert with some VBA code to perform the Tick Checkbox action.
Also please let me know if any additional information is needed.
<input class="check" submitname="chkPropLinkId" type="checkbox" value="120633"></input>
I got the answer from different site. Below is the workable VBA code for the query,
Set elems = HTMLDoc.getElementsByClassName("check")
For Each e In elems
If (e.getAttribute("value") = "120633") Then
e.Click
Exit For
End If
Next e

VB.Net ComboBox (as Dropdown) not translating text to DisplayMember with Databinding

I inherited a fairly large project at work that is undocumented and written in VB (originally started pre .NET, ended around .NET 2). I'm in the process of updating / refreshing a lot of the code, but have run into an annoying issue that I haven't found the solution for yet. This system utilizes a UI, a Web Service, and a SQL DB.
Problem: I have a Databound Combobox (originally set to DropDownList - I'm changing it to DropDown, which is what started this mess - going back isn't an option) that is tied to a DataSet that comes from a Web Service. When a user types in the item they want manually, the data from the text field doesn't seem to associate itself with the DisplayMember, which forces the WS/SQL query to fail (it is sent a blank value when it's expecting a ValueMember). If the user types in a partial selection and then chooses the value they want from the DisplayMember list using the arrow keys or tab, the query goes off without a problem.
My Question: How do I get the text field to translate to the DisplayMember which will then properly tie itself to the ValueMember which will then allow the query to execute correctly? Sorry for making this sound complicated or convoluted; I'm sure the answer is easy and I'm just glazing over it.
The relevant bit of code is:
With cmbDID
If dtsLU.Tables.Contains(reqTable) = True Then
.DataSource = dtsLU.Tables(reqTable)
.DisplayMember = "zip"
.ValueMember = "gridID"
End If
End With
cmbDID.DataBindings.Clear()
cmbDID.DataBindings.Add("SelectedValue", dtsData, strDT & ".gridID")
I've tried changing "SelectedValue" to "Text", which almost works - but it directly translates to gridID and skips zip which ends up with an incorrect Web Service response since the zip and gridID field values are not synced (zip (DisplayMember) may be 5123 while gridID (ValueMember) may be 6047). I've tried changing "SelectedValue" to "SelectedIndex", and that got me no where.
Any help is greatly appreciated.
EDIT
To add some clarification to the process, the below pseudo code / description is roughly what happens. I could post the whole module, but I feel that would just muddy the whole question even more.
Private Sub A
FormAlpha is created with 1 ComboBox in the form of a DropDown
This DropDown is populated with a DataSet
DataBinding with a blank DataSet is added to the control to keep track of the users input
End Sub
lblSubmit_Click event is triggered on FormAlpha by the user after they have populated the DropDown with their data. lblSubmit_Click calls Private Sub Submit
Private Sub Submit
BindingContext(DropDown DataSet, tableName).EndCurrentEdit() is called
DataSet.HasChanges() is processed
If changes are present, changes are processed
HERE lies the problem
If the user has manually typed in the DropDown field, but not hit an arrow key or tab, then the DataSet registers a change, but returns a null value in all fields - it knows something was entered, but that data apparently didn't pass through the DataSet for the ComboBox (ListItems or SelectedIndex didn't change / fire I'm guessing). If the user selects the item with the arrow keys, the DataSet has the proper input (I'm assuming the Data was validated by the control at this point).
If the processed data is good, a value is entered into the database
If the processed data is bad (empty), an error is returned
End Sub
If the above can't be solved with what I've provided, but someone still knows a better way to handle this type of situation, I'm all ears. Rewriting the module isn't ideal, but fixing this problem is a necessity.
Alright, while this fix may not be ideal, it is a fix none the less.
The bare bones problem was that the text value of the DropDown wasn't causing the data to actually affect the SelectedIndex / SelectedValue of the control unless you interacted with it using the arrow keys or a mouse click. So, while the DropDown would read "1234", in reality the control saw "".
The fix I have in place for this is simply calling comboBox.text = comboBox.text whenever the user hits the submit button.

How to get a post value in VB.Net

I need help with getting a Value posted from a form in VB.Net.
At the moment there is a form on a php website that is posting 2 values through to me.
name=Max
email=test"test.com
If i was using php i would use :
$name = $_POST['name'];
$email = $_POST['email'];
Now the above fields are now captured within a variable.
How do i do the the same thing in VB.NET
I cannot tell if you are referring to Web text box's or PHP forms but I can help you with Web text box's..
Your question is unclear, but I will try my best.
Assuming you want to get a textbox's value into a variable. You would do like so:
Example Textbox:
<asp:TextBox ID="ExampleTxtBox" runat="server" AutoPostBack="True"></asp:TextBox>
If you want to assign the values on a certain command, for example, a button click. You would put this into the button click handles of the button.
Assuming you want to get the current text/value from the form's text box:
Dim VariableOfTextBox As String 'Creates your Variable
VariableOfTextBox = ExampleTxtBox.text 'Assigns the Value from your Text Box