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.
Related
I'm wanting a button to perform multiple actions. when clicked it should:
add 1 to dial attempts field
change the "leagGenOutcome" to "no answer"
the problem is that the "leadGenOutcome" is a dropdown field taking it's options from another table.
I used this VBA code which works for a field with no drop down, but doesn't work on the drop down field.
Private Sub AddDialAttBTN_Click()
DialAttempts = DialAttempts + 1
LeadGenOutcome = "no answer"
End Sub
I know I must be missing something simple to get this to work. any help is much appreciated.
EDIT
by "doesn't work" the DialAttempts counter ticks up as it should but a "run time error" displays stating "the value you entered isnt valid for this field"
LimitToList property is Yes
"no answer" is a listed item
the field that LeadGenOutcome is bound to is called LeadGenOutcome01 in a form called LeadGenOutcomes.
currently it's a test database which I am using to learn how best to arrange and format.
changed "no answer" to "2" which is the ID for that response in the linked form. I had thought that it would display as "2" and not the associated text. this is not the case. thank you June7 for the assist.
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.
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
I've looked at many examples on how to log in to a website using vb. But somehow it keeps saying the password is incorrect.
Let me explain:
I'm trying to log in to this website using vb. I have managed to fill in the username and the password using
wb1.Document.GetElementById("Username").SetAttribute("Value", "myusername")
wb1.Document.GetElementById("Password").SetAttribute("Value", "mypassword")
I can see them being filled in, but upon clicking on the login button it says the password in incorrect. When I try to fill in the password by hand (username by program) and click the button it does work.
The difference between the two instances? When I do it manually the letters I type become dots. But when I do it via my program the letters do not change but remain letters. I think this is part of the problem, but I'm not entirely sure.
I've tried to change other items as well such as OuterHTML from the element Password. I could see which items were adjusted when I manually entered the password. And then I used those values. This didn't work. But then again, it was hard to see what exactly changed, so maybe I missed something.
One thing I noticed while doing to was when I manually entered the password Value was changed to "". Should I put my password in a different attribute? I'm guessing the password should be send encoded to the server?
This is the code for the password field on the website
<div class="jNiceInputWrapper jNiceSafari FieldPosition col2">
<div class="jNiceInputInner">
<input type="password" name="Password" id="Password" class="jNiceInput" placeholder="Wachtwoord" onkeypress="return SubmitOnEnter(this,event)" />
</div>
</div>
I really hope someone can help me with this problem. I've been working on it all day and just can't figure it out.
EDIT:
Thanks to Mr CoDeXeR I finally figured it out!
The code that solved the problem:
wb1.Document.All("Username").SetAttribute("value", "myusername")
wb1.Document.All("Password").SetAttribute("value", "mypassword")
Dim elements As HtmlElementCollection = (wb1.Document.All.GetElementsByName("Password"))
For Each element As HtmlElement In elements
element.InnerText = "mypassword"
Next
Removing either the setattribute value or the innertext will lead to failure.
Try this, don't use GetElementsByID, use Document.All instead. You want to pass the element's name attribute value to all, you may be just missing some of them...
wB1.Document.All("Username").SetAttribute("value", Username)
wB1.Document.All("Password").SetAttribute("value", Password)
Let me know how this works out for you
EDIT
Upon looking at this more, we can't use the ways we tried since it's a masked input. Instead we can loop through the document and set the inner text of that element...
' Loop through elements until the element is found
Dim elements As HtmlElementCollection = wB1.Document.All.GetElementsByName("Password")
For Each element As HtmlElement In elements
element.InnerText = "your password"
Next
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.