Programmatically input angularjs text field using javascript/VBA - javascript

I am web scraping from AngularJS application using Excel VBA. I am trying to enter value in text-input by using something like- ie.Document.getElementsByTagName("button")(15).Value = "112233"
I also tried- ie.Document.parentWindow.execScript "document.getElementsByTagName('button')[15].Value = '112233';
None of them is working. I have search few other posted questions but problems still exists. The element is:
<input whole-number="" type="text" maxlength="20" class="......" ng-model="pList.pNumber" bs-typeahead="typeahead_ProjectNumber" placeholder="enter a value" data-provide="typeahead" ng-change="reduceScrollMax()">

I got the solution to the problem:
angular.element(document.getElementByTagName('input')[15]).scope().pList.pNumber = '112233';
followed by
angular.element(document.getElementByTagName('input')[15]).scope().$apply();
OR angular.element(document.getElementByTagName('input')[15]).scope().$digest();
Include the above mentioned in ie.Document.parentWindow.execScript "..." to run it using VBA.

Related

MaskedPassword.js: How to get actual value (plain text) in JS

I'm using MaskedPassword.js to mask a password field in my form as demonstrated below:
<input type="password" id="pwd" name="pwd" autocomplete="off">
<script type="text/javascript">
new MaskedPassword(document.getElementById("pwd"), '\u25CF');
</script>
I'm trying to retrieve the plain text value of this password field using Javascript but unable to do so.
I've already tried the following:
document.getElementById("pwd").value
document.getElementById("pwd").text
document.getElementById("pwd").defaultValue
document.getElementById("pwd").innerHTML
Can anyone help me get the actual value?
Assuming you are using a version of the code in this post (possibly this implementation), I believe you would find it in the hidden field that is generated by the code, like so:
document.getElementById('pwd-unmasked').value
After struggling a couple of hours, I finally found out the following fix that worked for me:
document.getElementById('pwd')._realfield.value
Posting it here might help someone else.

How to find id of input field when getElementById does not work?

I'm trying to write a userscript javascript code in Firefox that will fill out a form. The form can be found here. The first input to fill appears to have id = "txtFirstName" yet when I try to find the element using getElementById, my console log returns null.
This is the code I'm using.
console.log(document.getElementById("txtFirstName"));
I eventually want to use a bunch of statements like:
document.getElementById("txtFirstName").value="SeanM";
How can I find the id of the input field so that I can assign a value to it?
Nested very deep in their code is this:
<input name="txtFirstName" id="txtFirstName" maxlength="20" value="" required="required" autofocus="autofocus" type="text">
I didn't wait for my DOM to fully load. Thank you all for the help.

Excel VBA - Manipulate Javascript

I have researched stackoverflow and other sources for many weeks for an answer to this question but have not been able to uncover an answer. I appreciate that there may be other posts that indirectly deal with the topic, but nothing seems to address the requirements of the specific example I have in mind, so I'm taking the plunge and posting. My request:
On the website www.4-traders.com there's an input box located at the top center of the page for entering a company name or stock ticker symbol. The page contains code that calls a javascript function as one types into the input box. The javascript searches a database for the best matches to the text being input, and the output of the javascript function is presented as a floating list box that one can select from. The code for this component of the page is as follows:
<td class="recherche_bl">
<input type="hidden" name="lien" value="recherche">
<input onblur="GlobalSearch.ACblur();" onkeyup="GlobalSearch.ACkeyUp(event)" onkeydown="return GlobalSearch.ACkeyDown(event);" autocomplete="off" type="text" name="mots" id="autocomplete" class="inputrecherche" value="Symbol or Keyword(s)" onclick="document.recherche_menu.mots.value='';GlobalSearch.LoadHisto()">
<input type="image" src="/images/loupe_recherche.png" class="htZo" align="absmiddle" onclick="document.getElementById('noredirect').value='1'">
<input type="hidden" name="RewriteLast" value="zbat">
<input type="hidden" id="noredirect" name="noredirect" value="0">
<input type="hidden" id="type_recherche" name="type_recherche" value="0">
</td>
GlobalSearch is the javascript function I'm interested in. I'd like to get Excel VBA to somehow select from the output of the GlobalSearch function after a value is input into the form. I currently have to use sendkeys to accomplish this, which as everyone knows has a number of drawbacks and requires that an Internet Explorer windows is open at the time. Here is the code I'm currently using for this piece:
The value of Ticker is set before this part of the code.
.document refers to an Internetexplorer.Application object I have created earlier on in the code.
PauseTime is a procedure used to delay the execution of code.
The two lines involving sending a 'space' and 'backspace' key are used to get the javascript to run (it doesn't seem to run without some manual user input). Once the javascript runs I want the procedure to select the first instance in the list box, so I send a 'down' key and then an 'enter' key.
.document.recherche_menu.mots.Focus
.document.forms("recherche_menu")("mots").Value = Ticker
PauseTime (2)
Application.SendKeys (" ")
Application.SendKeys ("{BS}")
PauseTime (2)
Application.SendKeys ("{DOWN}")
Application.SendKeys ("~")
I would really appreciate some help to figure this out. I think the real issue is that I don't have a deep enough understanding of javascript to code what I need to into Excel VBA. Thanks in advance for your help.
Constantine

AngularJS - ng-model not working with bootstrap directives

I am using AngularJS for my project and I am new to it. But I liked its features and very convenient for development as well. But I came up with the following issue and didn't know to get out of it.
I have a multi view application. The following code is a part of signup view. This view gets displayed when the signup button is pressed. Now the issue is, in the 4th and 5th line below, I have attached a ng-model attribute to and I am able to print the number obtained using {{num}} directive. However, the ng-model num2 below is not getting displayed as above. All I get is the static text {{num2}} being displayed. Why is it not working like the previous case?
<form role='form' action='#/app/register_db' method='post'>
<h1><small><b>Sign Up Information<b></small></h1>
<br>
<input type='text' ng-model='num'>
<h1>{{num}}</h1>
<div class='row'>
<input type='text' ng-model='num2'>
<h1>{{num2}}</h1>
<div class='col-xs-5'>
<input type="text" class='form-control' id="fn" name='firstname' ng-model='ng-firstname' placeholder="First Name">
</div>
</div>
...
...
I am new to AngularJS and I am very quickly grasping concepts. So if I am missing something, then please guide me through the right path and help me fix this issue.
I am using angularJS and Bootstrap CSS.
Thanks.
You should get the following error message in your browser's console:
[ngModel:nonassign] Expression 'ng-firstname' is non-assignable. Element: <input type="text" class="form-control" id="fn" name="firstname" ng-model="ng-firstname" placeholder="First Name">
As ng-model="ng-firstname" is not a reference by name, but an expression AngularJS will try to evaluate, so simply not using a dash will fix that. What happens when you break the code there is AngularJS basically stops, and anything else AngularJS would usually do in elements that follow, simply doesn't happen.

Validating URL in dojo textbox

While trying to validate URL input by user in ValidationTextBox but there is nothing I could find for validating URL input like "www.google.com" and "http://www.google.com"
<input dojoType="dijit.form.ValidationTextBox" regExp="dojox.validate.regexp.url" tooltipPosition="below" required="true" placeHolder="Enter Rule url" type="text" name="ruleUrl" id="ruleUrl">
The above doesn't work. Any alternative for validating URL's?
Are you sure you added dojox/validate/regexp to your modules in a require()? Because the code seems to work perfectly. I also made an example JSFiddle.

Categories