How To Login on website? Password as value not accepted - vb.net

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

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.

getting value of attribute to string vb.net

I want to get the value of the src attribute (https://www.google.com) to a string from a web browser HTML elements. The code of element is:
<img src="https://www.google.com" height="500" width="500">
Code I have tried is:
For Each o As HtmlElement In WebBrowser1.Document.GetElementsByTagName("img")
If o.GetAttribute("height") = "500" Then
Dim url As String = o.GetAttribute("src").ToString
Exit For
End If
Next
String url is empty every time I also tried to get url in textbox but its also empty.
problem is that is not a server side control, it is plain html. to make matters worse there are not classes or ID's to make it easier to isolate which control u want to target. Also javascript could be generating that image so that could make it harder.

Copy Value from combo list on login screen to username field on new form

Newer to access...I am trying to copy the value selected from the combobox on the log in screen to a field on the new form that opens after successful login.
The field I need copied is called cmoemployee on the Login form.I need that to go to the username field on the mainframe form.
Any help would be greatly appreciated! I have tried many different ways but I can't seem to get it.
Haha,
I actually know what you mean here. This can be a complete pain as the variables are deleted when you open a new form In general it is better to show what you have tried so people are able to help you fix it. Anyway, I've tried to do this so I know how frustrating it can be. There are two main ways that this can be done. You can open the form with openargs (I do not think this is a good option for you as you will have to have the openargs constantly transferring from one form to the next and will be cleared if one form misses them.
A better option would be to use tempvars which are not deleted. This is the code I used to do something similar:
I am going to assume your combobox is two columns (but only displays one) and the bound column is the primary key to an employee table. In which case this would work (or you can modify it to meet your needs)
Log in:
'Check Password (or however you check it
If StrComp(txt_Password, DLookup("[Password]", "tbl_Employee", "[ID] = " & cmoemployee), 0) = 0 Then
TempVars.Add "MyEmpID", cmoemployee.Value 'TempVars will store the combobox value
Else
Msgbox "Incorrect Password Please try again"
End If
On Load event of mainfraim form:
[UserName] = TempVars!MyEmpID
That should get you started, so you can build the rest. Let me know if you have any questions.

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.