How can I make a powershell script click on or fill an element without a name or and id? - powershell

I'm trying to write a powershell script for loggin in automatically on a website (in IE) and managed to fill the user name value based on it's ID but the password field and the login button have no ID at all. Password field has a name but I can't find a way to use that and login button doesn't even have a name on the website.
User name field:
<input tabindex="1" class="beviteliMezo" type="text" id="nev" name="nev" size="20">
As you can see the User name field has an actual ID so it's easy to do. But...
Password field:
<input tabindex="2" class="beviteliMezo" type="password" name="pass" size="20">
I'm trying to fill it like this:
$ie.Document.getElementByID('password field ID...').value = 'myPassword'
Login button:
<input tabindex="4" type="submit" value="Belépés!" class="submit_btn">
I'm trying to click on it like this:
$link=$ie.Document.getElementByID('login button ID...')
$link.click()
Since none of these elements have an ID, that one won't work. Do you have any suggestions?

Related

Prepend a form field response in Angular 2

I'm building a registration form in Angular 2 that asks a user to provide their website's URL before submitting.
When the form is submitted, I need the provided URL to be in the style of "http://www.google.com". To steer the user towards that format, I want the form field to autofill the initial "http://" as soon as the user clicks on the field (or when the user begins typing - either case would be acceptable). Currently I have placeholder text in the field that says "Please provide your website's URL", but I'm having trouble making the "http://" prefix appear when the user actually clicks on the field or starts typing.
Any ideas would be appreciated. Here is what the form field looks like when the user clicks on it. It's contents should switch to "http://" when clicked or typed in. Here is what the code looks like at the moment:
<div class="form-group">
<input
class="form-control"
type="text"
name="companyUrl"
[(ngModel)]="user.companyUrl"
placeholder="Company url"
required pattern='https?://.+'
#companyUrl
>
<div *ngIf="companyUrl.errors && (companyUrl.dirty || companyUrl.touched)" class="text-danger">
<div [hidden]="!companyUrl.errors.required">
Company URL is required.
</div>
<div [hidden]="!companyUrl.errors.pattern">
URL should begin with http:// or https://
</div>
</div>
<div>
Add a function to add the prefix on click event of the input.
Something like below:
<input #companyUrl (click)="addHttpPrefix()" >
And in this function
1. Get the value of companyUrl.
2. Check if it begins with http then skip else prepend with http://
if(companyUrl.indexOf('http') > -1) {
companyUrl = 'http://' + companyUrl;
}
This way when the user initially clicks on the input http:// would be appended.
if the (click) event does not meet your requirement you can try using (change) or other events.

Spring MVC how to handle binding when editing objects

I'm kind of newbie with Spring MVC - I have seen tons of tutorials so far, but just started developing. I've just come across this problem:
SUMMARY: I have a form with a table containing lots of users loaded from DB and backed in the spring model. I want to have an edit button for each user, and I want to bring up another form in order to edit that user, and still having that user backed in the model so I don't have to disclose id's or map users to random keys.
I have a List<User> object that I retrive from database through a #Service bean, and then I pass this list to my UserController bean. Then, in my controller:
#RequestMapping(value="/users", method = RequestMethod.GET)
public ModelAndView showUsers() {
List<User> users = userService.getUserList(); //Get from DB. Returns some users.
UserSet uset = new UserSet(); //Custom object backing the list.
uset.setUserList(users);
return new ModelAndView("users", "userset", uset);
}
This returns the view users.jsp and displays the user list in a table using a form:
<form:form action="#" method="post" modelAttribute="userset">
<table>
<tr>
<th>N.</th>
<th>Name</th>
<th>Email</th>
</tr>
<c:forEach var="user" items="${userset.userList}"
varStatus="status">
<tr>
<td align="center">${status.count}</td>
<td><input name="userList[${status.index}].name"
value="${user.name}" id="name_${status.index}" /></td>
<td><input name="userList[${status.index}].email"
value="${user.email}" id="email_${status.index}" /></td>
<td><input type="button" value="Ed." id="edbtn${status.index}"
class="edbtn" /></td>
</tr>
</c:forEach>
</table>
<input type="submit" value="Save" />
</form:form>
Now, you can see there's an edit button <input type="button" value="Ed." id="edbtn${status.index}" class="edbtn" /> for each user. What I want to do is to make a new single-user form appear when I click on that button, and have my User object binded to it, so that if I change the name and the email, I can still get the ID on the server side in order to update it in the database. The multi-user form above should have all the fields disabled or shown as labels - I don't want to change things there; I just want to show them there and have the button to open a popup or floating div with the actual single-user form inside.
By the way, I'm trying to capture the edited user with the following controller:
#RequestMapping(value="users/edit", method = RequestMethod.POST)
public String edit(#ModelAttribute(value="user") User user, BindingResult bresult) {
/* Do something here with the user */
/* Currently the ID returned from user.getId() is null, but the original user shown in the form has an ID != null */
return "redirect:/users";
}
And I'm sending the edit request through jQuery:
jq("#edituserbtn").click(function() {
jq.post("users/edit", {
name : jq("#edfrm_n").val(),
email : jq("#edfrm_e").val(),
}, function(data, status) {
//jq("#changing").text(data + "; " + status);
});
});
Note that #edfrm_n and #edfrm_e would be the id's of that single-user form I want to use here, instead of sending back the whole form. Using jQuery I'd also popup this single-user form and place it in front of everything, in the middle of the screen.
How can this be accomplished?
P.S.: This may not be the best approach for the editing feature. In such case, I'd really appreciate that you provided me with some hints.
Thanks
I think you should do some change about the existed code. You should set user id as user edit button value, you can write a js function which arguments are user id, user name and status. bind it to the buttons. when you click the edit button that it will run the js function and pop-up a new dialog in this dialog that you can get the three arguments and show them. The dialog I recommend you using jQuery dialog, since you have added the jQuery library. And you should add save button in this dialog and after edit the user data, just click the save button and call ajax to send the data to server, because it has id, so you know which one that will be updated. and the server will return the status of updating operation, in the ajax callback function, you do the other thing with the status. if success, close dialog and refresh main window, if failed, pop-up the alert dialog.
Well, I thought Spring was doing some magic I now think it is not doing. As zeroflagl said, Spring needs to know what you are trying to update, so some sort of ID, or the actual DB ID, must be provided.

When logging into Facebook through application the page refreshes

The first page of the application passes a value over to the next page using a text box. If the user isn't logged in then it will display a login link that will allow them to do so. Whenever they click the link the page will refresh which drops the value for the variable passed over from the first page.
This is the code for the input box on the first page (HTML)
<form action="verify.php" METHOD=post>
Enter a School:
<input type="text" name="school" />
<INPUT TYPE=SUBMIT VALUE="GO">
</form>
This is the code for the second page to check if they are logged in or not (PHP)
$user = $facebook->getUser();
if ($user == 0){
$loginUrl = $facebook->getLoginUrl();
echo ( '<b>Please Login before proceeding.</b>' );
echo ( '<br />' );
Store the value you need to save before/after login in a session variable, or apprend it to the variables used in your redirect_uri (generated in the getLoginUrl() function)
Bear in mind you'll need to keep the same redirect_uri value when you exchange the code for an access_token in the second step of the server side auth

how to automatically submit a spring security login form using JSP code?

I'm using spring security for normal login form, where users register and then enter their username and password to login. I'm using login with facebook and login with google options, I'm able to authenticate users and finally get user's info like email, first name, last name etc, After logging into either fb/google I'm using fb/google user email(unique) as user name and system generated password as login credentials so that these values will be entered automatically to spring security login form and then if I click on submit button he/she will be able to login and then session handling will be taken care by spring security as in case of normal user who registers in my website.
Since, all the steps described above are automated except last step i.e. submitting the form
I want to automate the last step also using either javascript or JSP. i tried submitting the form using javascript inside JSP but its unable to
<%
if(Success_login_with_facebook/Success_login_with_google)
{
email = fb_email/google_email;
Sql query to get username and password from db using email;//unique row will be returned
uname_db = username;
uname_pass = password;
out.println("<script>document.forms('login').submit();</script>");
}
%>
<div id="autologin" style="display:none">
<form name="f" id='login' action="<c:url value='j_spring_security_check'/>" method="POST" >
User ID <input size=35 type='text' id="first" name='j_username' value='<%=uname_db %>'/>
Password<input size=35 type='password' name='j_password' value='<%=pass_db %>'>
<input type="hidden" name="_spring_security_remember_me" value=true>
<input style="height:30px" name="submit" type="submit" value="Sign In">
</form>
</div>
Your solution should work, but it's missing one thing. You need to make sure that the form exists before trying to submit it wis JavaScript. In your example, you're doing an out.println above the form. Move this to below the form, and the JavaScript should work fine.
The reason why it did not work is because the html form has submit button name as "submit", and if we try to run the javascript document.forms['login'].submit(); it will not submit the form. If the form submit button name is other than 'submit' then it will work.

URL Redirect based on input but if input url does not exist send back to same page

This code is almost perfect for what I need:
<form onsubmit="location.href='http://www.mysite.com/' + document.getElementById('myInput').value; return false;">
<input type="text" id="myInput" />
<input type="submit" />
</form>
The only thing missing is if they user puts in an input that does not exist I want it to take them nowhere or redirect back to the same page. Right now it takes them to an error page and they have to use the back button to go back and try again.
Any help will be greatly appreciated.
Thank you
Could you perhaps write a small PHP script that you use as the form action? Inside this script, you could check the supplied user input and validate that the URL exists. If it does, you could do a header() redirect to the given page. If it does not exist, you could redirect them to the desired page.
<?php
$input = $_POST['myInput']; // You'll also need to add in a name='' tag in the HTML!
$desired_page = ''; // page you want to go to if inputted file cannot be found
if (file_exists($input)) {
header("Location: $input");
}
else {
header("Location: $desired_page");
}
It'd need a lot of refining, but that's the idea. Would that do what you want?