Tick Checkbox on Webpage using VBA - 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

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.

Conditional visibility on MS Access Form - how to write in VBA or Macro

I have some very (very) basic MS Access knowledge. I'm trying to expand a bit into either VBA or macros as I'd like to put in some conditional visibility for my form. Basically, I have a checkbox. If it's checked, I want three or four more fields to pop up. Someone was able to point me to a basic VBA formula of if (this checkbox) = true then, (fieldx).visible = true, else, (fieldx).visibility = false, end if.
But I'm so new to this that I need more help and explanation. I tried putting it in but couldn't get it to work (no error message, just nothing changed at all).
Specific questions:
-Does this formula seem right?
-If I want multiple fields to be visible, can I combine them into one formula or should I create a new "if" statement for all?
-Where do I enter this code? I'm running the Office 365 version. For all I know, I'm not even putting it in the right place.
-How do I determine the field names to replace the (this checkbox) and (fieldx) in the formula? I tried entering the name I title the fields as, but with the spaces in the name I got an error message, and without the spaces nothing happened. Is there a specific naming convention to turn the field names into formula-appropriate titles? Is the name listed somewhere?
-Once I get the formula entered, is there something I have to do to get it to run/take effect? I tried saving, closing and reopening with no changes.
-Is this the best way to go about this?
If there's anything else you think I should know, I would love to hear it - but please keep in mind I'm very new to this so if you could keep it at "dummy" or ELI5 levels of explanation, I'd appreciate it!
after creating a form with 4 textboxes and a checkbox put the form in design mode (lower right corner has design mode selected, select a textbox and hit property sheet on the ribbon (or f4).
On the property sheet note the visible property. set the visible property to false. Now the textbox will be invisible when the form starts.
Tip you can select all the textboxes at the same time and set their properties all at once.
Every control on the form and even the various parts of the form have properties you can set and play with. For instance you can give any name you want to any control. On the property sheet go to the other tab and set the name property.
Tip: choose a name you you will remember without having to look it up and describes the controls function.
Next select the checkbox (not the checkbox's label). On the property sheet go to the event tab and select the on click event. hit the ellipsis and choose code builder. Access is Event Driven. We want the textboxes to appear when the checkbox is selected so we put that code in the checkbox click event.
after choosing code builder we get the code window where we can browse among all the events for all our forms. for now all you should see is something like:
Private Sub mycheckbox_Click()
End Sub
So insert some code to handle the checkboxes like:
Private Sub mycheckbox_Click()
If mycheckbox = True Then
txtbox1.Visible = True
txtbox2.Visible = True
txtbox3.Visible = True
txtbox4.Visible = True
Else
txtbox1.Visible = False
txtbox2.Visible = False
txtbox3.Visible = False
txtbox4.Visible = False
End If
End Sub
now when the checkbox is not checked no textboxes are visible.
but when the checkbox is checked they appear

Using VBA to click on a button that has no "Id" nor "Value" I i can use to click

I have tried different methods such as using trying to use the tab key to get to it but unfortunately it is not in the tabbing sequences, so I could not send the focus on it to be have my RPA click on it. Below is the HTML markup:
<td class="buttonSmall" onmouseout="this.className='buttonSmall'"
onmousedown="this.className='buttonSmallPressed'"
onmouseup="this.className='buttonSmall'"
onclick="openDualFacingWindow(getBillingCycleURL());">View</td>
Notice that I have tried to use the tag as follow
Set viewObject = Ie.document.getElementsByTagName("td")
For Each viewObj In viewObject
If viewObj.Value = "View" Then
viewObj.onclick
Exit For
End If
Next
It does not seems to work. Any help would be greatly appreciated

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

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.

How to raise event because a user didn't not select a checkbox option after choosing a certain value in a combobox?

I am new to vb.net and I have looked at other topics. I cannot find the answer I need. OK I have a combobox named cboRaceDesc and five checkboxes (CkRaceAfricanAmerican, ChkRaceAmerican Indian, ckRaceAsian, ckRacePacificIslander, and ckRaceWhite). I was going to post an image, but I cannot.
cboRaceDesc has two options...Hispanic and Other. If the user selects Other then they have to choose one of the five checkboxes or it will raise an exception when the record is being saved. I am assuming I would generate the code under the "save" button. I know I need to gather the following information in my code:
If cboRaceDesc.SelectedValue = Other Then
<I am not sure how to code the logic regarding the checkboxes>
<I know I need to use multiple else/else if statements>
<I know towards the end I would generate the exception>
End
Can anyone help me fill in the blanks or point me in the right direction? Thank you in advance.
If only one of 5 options can be selected then you should probably use radiobutton (with same group name) or radiobuttonlist control. Quick (and dirty) verification logic would be something like this:
If cboRaceDesc.SelectedValue = "Other" Then
if (CkRaceAfricanAmerican.Checked orelse
ChkRaceAmericanIndian.Checked orelse
ckRaceAsian.Checked orelse
ckRacePacificIslander.Checked orelse
ckRaceWhite.Checked) then
' show error message or throw exception
End if
End if
' save stuff