Get the last occurance of the an object - selenium

In my html page there is an option to add multiple "Resource Identity". When I add a new one, it it creates a new row with the following elements.
<tr>
<td width="150" valign="top">
<input type="hidden" name="expressions[0].checked"/>
<input type="hidden" value="B" name="expressions[0].expressionLabel"/>
<b>Resource Identity</b>
<input type="hidden" value="ResourceIdentity" name="expressions[0].parameterName"/>
<input type="hidden" value="ResourceIdentity" name="expressions[0].fieldName"/>
<input type="hidden" value="RF" name="expressions[0].fieldType"/>
<input type="hidden" value="" name="expressions[0].limitedValues"/>
</td>
</tr>
<tr>
<td width="150" valign="top">
<input type="hidden" name="expressions[1].checked"/>
<input type="hidden" value="B" name="expressions[1].expressionLabel"/>
<b>Resource Identity</b>
<input type="hidden" value="ResourceIdentity" name="expressions[1].parameterName"/>
<input type="hidden" value="ResourceIdentity" name="expressions[1].fieldName"/>
<input type="hidden" value="RF" name="expressions[1].fieldType"/>
<input type="hidden" value="" name="expressions[1].limitedValues"/>
</td>
</tr>
How do I find the last occurrence of <b>Resource Identity</b>?
I am trying to find out the name above the tag by using the below xpath, but it always evaluates to the find occurance as selenium scans the html from top to bottom.
driver.findElement(By.xpath(//b[text() = 'Resource Identity']/preceding-sibling::input[1])).getAttribute("name").toString();
If there are multiple "Resource Identities", then how do I go to the last "Resource Identity" and find the name?

Use last():
(//b[text() = 'Resource Identity']/preceding-sibling::input[1])[last()]

Related

how to submit form data with multiple buttons

I want to send data to database table. but there are two submit buttons. 1.Accept 2.Reject. When you click the Accept button, the database will receive the input "value = accepted," and when you click the Reject button, the database will receive the input "value = rejected." The problem is that if you click on any button, "input value = accepted" is sent to the table.
This is my form.
#foreach($attendance as $request)
<form class="d-sm-inline-block" method="POST" action="/update" enctype="multipart/form-data">
#csrf
<tr>
<th scope="row">
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">{{$request['id']}}</label>
<input type="hidden" value="{{$request['id']}}" name="id" class="form-control">
</div>
</th>
<td>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">{{$request['name']}}</label>
<input type="hidden" value="{{$request['name']}}" name="name" class="form-control">
</div>
</td>
<td>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">{{$request['class']}}</label>
<input type="hidden" value="{{$request['class']}}" name="class" class="form-control">
</div>
</td>
<td>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">{{$request['roll_number']}}</label>
<input type="hidden" value="{{$request['roll_number']}}" name="rollnumber" class="form-control">
</div>
</td>
<td>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">{{$request['subject_name']}}</label>
<input type="hidden" value="{{$request['subject_name']}}" name="subject" class="form-control" >
</div>
</td>
<td>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">{{$request['attendance']}}</label>
<input type="hidden" value="{{$request['attendance']}}" name="attendance" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
</td>
<td>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">{{$request['status']}}</label>
<input type="hidden" value="{{$request['status']}}" name="status" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
</td>
<td>
<div class="mb-3">
<input type="hidden" value="Accepted" name="status" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<input type="hidden" value="Rejected" name="status" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
<button type="submit" class="btn btn-success" action="action" value="accept">accept</button>
<button type="submit" class="btn btn-warning" action="action" value="reject">Reject</button>
</tr>
</form>
#endforeach
remove:
<div class="mb-3">
<input type="hidden" value="Accepted" name="status" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<input type="hidden" value="Rejected" name="status" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
and change this:
<button type="submit" class="btn btn-success" action="action" value="accept">accept</button>
<button type="submit" class="btn btn-warning" action="action" value="reject">Reject</button>
to:
<button type="submit" name="status" class="btn btn-success" action="action" value="accept">accept</button>
<button type="submit" name="status" class="btn btn-warning" action="action" value="reject">Reject</button>
Your submit buttons have no name attribute so their values won't be there in the request.

XPATH for checkbox where id, type and name is same in Selenium

please look the Below code:
what will be the XPath for id= idConfirmedCheckbox?
<td class="tdCenter">
<input id="idConfirmedCheckbox" type="checkbox" onclick="return idConfirmedClicked(this);" name="idConfirmedCheckbox"/>
<input id="Customer_Person_Identifications_Identification_0_Confirmed" type="hidden" value="N" name="Customer_Person_Identifications_Identification_0_Confirmed"/>
<input id="Customer_Person_Identifications_Identification_0_NotConfirmedDisabled" type="hidden" value="" name="Customer_Person_Identifications_Identification_0_NotConfirmedDisabled"/>
</td>
<td class="tdCenter">
<input id="idConfirmedCheckbox" type="checkbox" onclick="return idConfirmedClicked(this);" name="idConfirmedCheckbox"/>
<input id="Customer_Person_Identifications_Identification_1_Confirmed" type="hidden" value="N" name="Customer_Person_Identifications_Identification_1_Confirmed"/>
<input id="Customer_Person_Identifications_Identification_1_NotConfirmedDisabled" type="hidden" value="" name="Customer_Person_Identifications_Identification_1_NotConfirmedDisabled"/>
</td>
Try below Xpath:
//input[#id='idConfirmedCheckbox']
OR
//input[#id='idConfirmedCheckbox' and #type='checkbox']
OR
(//input[#id='idConfirmedCheckbox' and #type='checkbox'])[1]
Change the array to 1 to 2 or 3 as per required

Error on file size when uploading the image

I am trying to upload a file using the following script. The script uploads the file via browse button, but when I click on the upload button, it gives an error //Error on file size.
FYI - manually upload for the same file is successful
My script:
driver.findElement(By.xpath(".//*[#id='fileUploadInput']/div/div[2]/input[2]")).sendKeys(file_upload);
driver.findElement(By.id("btnCreativeHostingFileUpload")).click();
HTML:
<tr id="fileOas" style="display: table-row;">
<td align="left" style="height:25px;">File Name</td>
<td nowrap="" align="left" style="height:40px;">
<input type="hidden" style="width:250px" name="uploadFileName" id="videoUploadFileName" value="tag.png">
<div onclick="setActiveUploadForUploadAll();" style="height:40px;">
<!-- <iframe id="sUploadAll" name="sUploadAll" onmouseover="setActiveUpload('sUploadAll');" -->
<iframe width="470" height="40" frameborder="no" allowtransparency="true" scrolling="no" src="/richmedia/oas/FileUpload.do?nextAction=/oas/adwizard.banner.update.do&currentPage=/oas/adwizard.creative.index.do&fileCategory=image&fieldName=videoUploadFileName&previousFile=" onmouseover="prepareActiveUpload('sUploadAll');" name="sUploadAll" id="sUploadAll">
</iframe>
<input type="hidden" name="videoUploadFileNameFullUrl" id="videoUploadFileNameFullUrl" value="tag.png">
<input type="hidden" name="videoUploadFileDownloadUrl" id="videoUploadFileDownloadUrl">
<input type="hidden" value="" id="currentSelectFileId">
<input type="hidden" value="" id="currentSelectFileType">
<input type="hidden" name="uploadFileNameFullUrl" id="uploadFileNameFullUrl" value="tag.png">
<input type="hidden" name="dimensionWidth" id="dimensionWidth">
<input type="hidden" name="dimensionHeight" id="dimensionHeight">
</div>
</td>
</tr>
<div>
<div class="input_div">
<input type="text" readonly="readonly" class="file_input_textbox" id="fileName">
</div>
<div class="file_input_div">
<input type="button" value="Browse" class="file_input_button">
<input type="file" style="width:100px;" onchange="javascript: document.getElementById('fileName').value = this.value" value="" size="25" name="theFile">
</div>
<div class="upload_btn_div">
<button onclick="showProgressAndUpload(this.form);" name="btnCreativeHostingFileUpload" id="btnCreativeHostingFileUpload" type="button" style="margin-left: 10px" class="btn btn_gray"><div><p>Upload</p></div></button>
</div>
</div>
Looks like you are using wrong selector
Try this cssSelector
[type='file']
Or, that input tag has the name as well. So you can use theFile as By.name
So, far in that's the only file input tag I am seeing in the html you have provided
You can also do this with JavaScript executor in case the above does not work
String filePath = "the filepath with extension";
((JavascriptExecutor)driver).executeScript("document.getElementById('fileName').setAttribute('value', '"+filePath+"');");
driver.findElement(By.id("btnCreativeHostingFileUpload")).click();

Paypal: Passing Customer Name

I am creating a simple form with paypal checkout. I am looking to pass an additional name that is not the billing name to the checkout page. Is there any Paypal variable I may have over looked?
Here is the basic PayPal Standard Button HTML Variables Guide From the PayPal Developer site:
PayPal Standard Button HTML Variables Guide
Here is some basic Open PayPal Standard Source Button Code that can pass a customer name and customer phone number:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="youremail#email.com">
<input type="hidden" name="lc" value="US">Enter Amount<br />
<input type="hidden" name="item_name" value="Enter Amount">
<input type="text" name="amount" size=8>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted"><br />
<table>
<tr><td>
<input type="hidden" name="on0" value="Client Name">Enter Client Name</td></tr><tr><td><input type="text" name="os0" maxlength="200"></td></tr>
</table>
<table>
<tr><td><input type="hidden" name="on1" value="Client Phone">Enter Client Phone Number (no dashes or special characters)</td></tr><tr><td>
<input type="text" name="os1" maxlength="200"></td></tr>
</table>
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
This part of the button code controls passing the Client Name and Client Phone number to PayPal:
<table>
<tr><td><input type="hidden" name="on0" value="Client Name">Enter Client Name</td></tr><tr><td>
<input type="text" name="os0" maxlength="200"></td></tr>
</table>
<table>
<tr><td><input type="hidden" name="on1" value="Client Phone">Enter Client Phone Number (no dashes or special characters)</td></tr>
<tr><td><input type="text" name="os1" maxlength="200"></td></tr>
</table>

How to send the http get in Rebol to download an wordpress xml backup file?

I would like to use rebol to download an xml backup of my blog from
http://reboltutorial.com/wp-admin/export.php
the form is
<form action="" method="get">
<h3>Options</h3>
<table class="form-table">
<tr>
<th><label for="author">Restrict Author</label></th>
<td>
<select name="author" id="author">
<option value="all" selected="selected">All Authors</option>
<option value='1'>admin</option></select>
</td>
</tr>
</table>
<p class="submit"><input type="submit" name="submit" class="button" value="Download Export File" />
<input type="hidden" name="download" value="true" />
</p>
</form>
I guess I would first need to log in http://reboltutorial.com/login/ and then what after ?
Any code example to do similar stuff (getting the cookie, ...) ?
<form name="loginform" id="loginform" action="" method="post">
<p>
<label>Username<br />
<input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
</p>
<p>
<label>Password<br />
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
</p>
<p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Remember Me</label></p>
<p class="submit">
<input type="hidden" name="post-from" id="post-from" value="page" />
<input type="hidden" name="action" id="action" value="login" />
<input type="submit" name="wp-submit" id="wp-submit" value="Log In" />
<input type="hidden" name="redirect_to" value="http://reboltutorial.com/wp-admin/" />
<input type="hidden" name="testcookie" value="1" />
</p>
</form>
Try this
http://rebol.wik.is/Protocols/Http