iMacros Script
I Need to extract 3 radio buttons text, evaluate it against a stored option. So that the correct selection can be made. There are only 3 buttons but the options are dynamic. I can extract text, and if split can eval it with Gematria. My issue is splitting the text so it can be eval'd. The text is separated by
Example of the extraction SQF BOX
SQF BOX
Html I am pulling from
<td class="evenBand" width="60px" align="left">
<input type="radio" name="ordUom0" id="ordUomR0" tabindex="1001" value="SQF" onclick="checkHSUom(0,'SQF','BOX','','SQM',32.93,1.0,1712.36);"
>SQF
<br>
<input type="radio" name="ordUom0" id="ordUomI0" tabindex="1002" value="BOX" onclick="checkHSUom(0,'SQF','BOX','','SQM',32.93,1.0,1712.36);"
>BOX
<input type="hidden" name="orderedUom" id="orderedUom0" value=""
<="" td="">
</td>
DOES NOT WORK
SET !VAR3 EVAL("'{{!VAR2}}'.split(' ')[0].trim();")
SET !VAR5 EVAL("'{{!VAR2}}'.split(' ')[1].trim();")
SET !VAR6 EVAL("'{{!VAR2}}'.split(' ')[2].trim();")
DOES NOT WORK
SET !VAR3 EVAL("'{{!VAR2}}'.split(' ')[0].trim();")
SET !VAR5 EVAL("'{{!VAR2}}'.split(' ')[1].trim();")
SET !VAR6 EVAL("'{{!VAR2}}'.split(' ')[2].trim();")
Perhaps something like this will be helpful to you:
SET !VAR3 EVAL("'{{!VAR2}}'.split(/\s+/)[1];")
SET !VAR5 EVAL("'{{!VAR2}}'.split(/\s+/)[2];")
Related
I need to access the input field in the below html. The way the page is setup I need to chain using the 'Address Line 1' text and then sending text to the input field. The input field id changes and so doesn't the layout of the fields depending on user preference. I am struggling. If you need some more information feel free to ask I did not want to overload with too much information.
<td class="labelCol requiredInput">
<label for="00N36000000xina"><span class="assistiveText">*</span>Address Line 1</label>
</td>
<td class="dataCol col02">
<div class="requiredInput">
<div class="requiredBlock"></div>
<input id="00N36000000xina" maxlength="255" name="00N36000000xina" size="20" tabindex="4" type="text">
</div>
</td>
I have accessed like this:
element(by.css('div.pbSubsection:nth-child(3) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input'))
However depending on where the user puts the fields it can move around. So what I was hoping was to be able to access the label\ and use that to pinpoint its input field.
I don't know protractor but I cobbled together some code that hopefully will work or be close and I'll give you the thought process and some info and hopefully you can use it to fix my code, if needed, and solve the problem.
Start by finding an element by XPath, "//label[text()='Address Line 1']". This searches for a LABEL tag that contains "Address Line 1". Once you find that element, get the label attribute. From your HTML, this label is the id for the INPUT element you want. Now use the id to find the element and do with it what you want.
id = element(by.xpath("//label[text()='Address Line 1']")).getAttribute("label")
input = element(by.id(id))
input.sendkeys("some text")
Haven't tested this myself, but you could try something like this:
// $ is shorthand for element(by.css())
$('div.assistiveText').getAttribute('for').then(function (val) {
// locate the <input> by the value of the attribute on <label>
element(by.id(val)).sendKeys('abc'); // replace sendKeys with your intended function
});
Or if that first locator on the label isn't specific enough, swap out $('div.assistiveText') for element(by.cssContainingText('Address Line 1'))
I tried it for other attributes (I don't have a for attribute anywhere in my app) and it seemed to work for me.
Try this:
List<WebElement> elementList = driver.findElements(By.cssSelector("tbody > tr"));
for (WebElement element : elementList) {
if(element.findElement(By.cssSelector("td.labelCol > label")).getText().equalsIgnoreCase("Address Line 1")) {
element.findElement(By.cssSelector("input[type='text']")).sendKeys("textToInput");
}
}
I've been trying to fill some textboxes in geckofx 22.0.7. Most of them with success. There are a couple though that resist any change! Both of them allow only numbers to be typed. The first one (the one presented here) is used to receive a date entry. The user only types numbers (not slashes or dashes etc).
The html code follows:
<td class=" dataEntryCol4">
<input id="insertDate" class="ui-inputfield ui-inputmask ui-widget ui-state-default ui-corner-all" type="text" style="width:90px" tabindex="2" value="" name="insertDate" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false">
</td>
My code is this:
GeckoHtmlElement insertDate = document.GetHtmlElementById("insertDate");
insertDate.SetAttribute("value", "08/06/2014");
I also tried using
SendKeys.SendWait("08062014");
SendKeys.SendWait("{TAB}");
I can't get it to work. Any suggestions?
First cast GeckoHtmlElement to a GeckoInputElement then use the Value property.
GeckoInputElement insertDate = (GeckoInputElement)document.GetHtmlElementById("insertDate");
insertDate.Value = "08/06/2014";
(Edited to provide clearer example)
I have cakephp model structure of document->section->variables
In a form I want to be able to list all variables, but nested within document and then section levels. That bit is fine.
I want check boxes alongside each item at the variable level - to allow selection of variables.
I want a checkbox at sectionlevel, that when selected will select all the checkboxes for the variables in that section.
I want a checkbox at document level so that when selected it will select all checkboxes for the variables for that document (ie in all sections.)
To facilitate this I have named the checkboxes thus (well, I have set the ids)(pseudo code):
document level: id = Document id
section level id = Document id_Section id
variable level id = Document id_Section id_Variable_id
My hope this that if I select the section level checkbox I can set all the variable level checkboxes FOR THAT SECTION by using the Document id_Section_id stub at the beginning of all the ids for the variable level checkboxes... but maybe I am grasping at straws?
Here is a sample of checkboxes in levels: (apologies for layout)
<?php
//Document level
//all of this within a ForEach loop for documents
echo "<table>";
echo "<tr><td>Collection dates</td><td>".$project_document['data_collection_dates']."</td>";
echo "<td>Select (toggle) all variables"
.$this->Form->checkbox($project_document['id'], // note that this sets the chkbox id to the value of the current document id
array('hiddenField' => false,'onclick'=> 'SelectSection(this,this.name,this.checked);'))
."</td></tr>";
echo "</table>";
foreach ($project_document['ProjectDocumentSection'] as $project_document_section):
echo "<h4>" . $project_document_section['title']. "</h4>";
echo "<table>";
echo "<tr><td>Collection Method</td><td>" . $project_document_section['method']. "</td></tr>";
echo "<tr><td>Collection objective</td><td>" . $project_document_section['objective']. "</td>";
echo "<td>Select (toggle) all section variables"
.$this->Form->checkbox($project_document['id']
."_".$project_document_section['id'] // and here the chkbox id is set to combination of document id and section is (using _ as separator)
, array('hiddenField' => false))."</td></tr>";
echo "</table>";
echo "<table><tr><th>Full text</th><th>Type</th><th>Format</th><th>Codeset</th></tr>" ; // header for variable table
foreach ($project_document_section['ProjectDocumentSectionVariable'] as $project_document_section_var):
echo"<tr><td>".$project_document_section_var['variable_type']
."</td><td>".$project_document_section_var['variable_format']
."</td><td>";
echo "<td>".$this->Form->checkbox($project_document['id']
."_".$project_document_section['id']
."_".$project_document_section_var['id'], array('hiddenField' => false))."</td></tr>";
endforeach;
echo "</table>";
endforeach;
// and later endforeach for the document itself
?>
And when rendered this might look something like this;
<td>Select (toggle) all variables
<input type="checkbox" name="data[Project][11]" onclick="SelectSection(this,this.name,this.checked);" value="1" id="Project11"/>
// note that checkbox id and name include ref to document id (11)
</td></tr>
<h4>Details of Health Workers at Facility</h4>
<table>
<tr><td>Collection Method</td><td>FW completed evaluation on paper</td></tr>
<tr><td>Collection objective</td><td>blah blah blah blah</td>
<td>Select (toggle) all section variables
<input type="checkbox" name="data[Project][11_24]" value="1" id="Project1124"/></td></tr>
// note that checkbox id and name include ref to document id (11) and section id (24)
</table>
<table>
<tr><th>Full text</th><th>Type</th><th>Format</th><th>Codeset</th></tr>
<tr><td>Site</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_402]" value="1" id="Project1124402"/></td></tr>
// note that checkbox id and name include ref to document id (11), section id (24) and variable id (402)
<tr><td>Facility</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_403]" value="1" id="Project1124403"/></td></tr>
<tr><td>Name</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_404]" value="1" id="Project1124404"/></td></tr>
<tr><td>Position of Health Worker</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_405]" value="1" id="Project1124405"/></td></tr>
<tr><td>Description</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_406]" value="1" id="Project1124406"/></td></tr>
<tr><td>Interviewer Code</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_407]" value="1" id="Project1124407"/></td></tr>
<tr><td>Date of Facility Visit </td><td>Date</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_408]" value="1" id="Project1124408"/></td></tr>
</table>
Has anyone any advice on how to approach this? I am sure there is more than one way to kill this bird..
Thanks
Paul
IF I understand your question, just use the FormHelper to create your checkboxes - they'll include the model in their id, and you can then upon click use Javascript (jQuery makes it easy) to modify checkboxes that contain '_variable', or '_section'...etc
I can't quite get this to work.
My form has a number of inputs including one checkbox. In my cfquery, I just want to write some simple SQL content that tests to see if the checkbox is checked or not. But my code just ignores it completely. Here's the basics:
<cfform name="form" action="...." format="HTML">
....
<cfinput type="checkbox" name="search_NR" id="search_NR" checked="no" />
<cfinput type="submit" name="submit" value="Search" />
</cfform>
My cfquery is quite extensive, so I'll just put the part relevant to the checkbox here:
<cfif isDefined("form.search_NR")>
AND (tblMain.NR = true)
</cfif>
My thought was that the box wouldn't be defined if it wasn't checked. But whether or not I check the box on the form, the query just ignores this altogether. I just want to add tblMain.NR = TRUE to the rest of the SQL content when the box is checked.
<cfif StructKeyExists(form, "search_NR")>
AND (tblMain.NR = true)
</cfif>
This will correctly display current status and allow user to change if using both <cfForm> and <cfInput type="Checkbox">:
Note: Ensure that <cfParam> tag is before other references to the form element.
<cfparam name="form.search_NR" default="off">
<cfInput name="search_NR" type="Checkbox" checked="#form.search_NR is 'on'#">Some Text Here
When the <cfform> is submitted the value of search_NR is either 'on' or 'off' and can be checked in your query. Remember to add the form. to the element name:
<cfIf form.searchNR EQ 'on'>
...
<cfElse>
...
</cfIf>
Try using method="POST":
<cfform name="form" action="...." format="HTML" method="post">
Otherwise your variables are submitted via the URL scope.
I figured out a solution on my own...
In the form:
<input type="checkbox" name="search_NR" <cfif search_NR is "on"> checked</cfif> />
And on the processing page...
Before the cfquery:
<cfparam name="search_NR" default="off">
And in the query...
<cfif #search_NR# EQ "on" >
AND (tblMain.NR = true)
</cfif>
i have a jsp page where i have a input type file and i m allowing the user to browse files. i have one such input on jsp and the rest i m generating dynamically by javascript.
this is my jsp code:
<div id="labelContainer" style="display:inline">
<table align="center">
<tr>
<td align="left"><input type="text" id="label0" name="label0" size="15"></td>
<td align="center"><input type="file" id="filePath0" name="browsetrainset0"></td>
<td id="addlabel" ><img src="../images/add.png" title="Add Label" onclick="addLabel()"></td>
<td id="removelabel"><img src="../images/remove.png" title="Remove Label" onclick="removeLabel('labelDiv0')"></td>
</tr>
</table>
</div>
and this is my javacsritp code:
function addLabel(){
var text="";
lCount++;
text+=("<table id='labelDiv"+lCount+"' align='center'>");
text+=("<tr>");
text+=("<td align='left' style='display:none'><input type='checkbox' checked='true' name='labelchkbox'/></td>");
text+=("<td align='left' id='label'><input type='text' id='label"+lCount+"' name='label"+lCount+"' size='15'></td>");
text+=("<td align='center'id='filePath' ><input type='file' id='filePath"+lCount+"'name='browsetrainset"+lCoun t+"'></td>");
text+=("<td id='addlabel' ><img src='../images/add.png' title='Add Label' onclick='addLabel()'></td>");
text+=("<td id='removelabel'><img src='../images/remove.png' title='Remove Label' onclick=\"removeLabel('labelDiv"+lCount+"')\"></td>");
text+=("</tr>");
text+=("</table>");
document.getElementById("labelContainer").innerHTM L+=text;
}
but i m not able to retain the value of the file path i browse, on the jsp page once i click the add label and generate another input type file.
I am using IE7. Please tell me how to reatin the value of the browsed files so that i can use them further.
document.getElementById("labelContainer").innerHTM L+=text;
Never, ever use += on innerHTML. It does not do what you think.
Instead, it laboriously serialises the entire contents of the div into HTML, adds your string onto the HTML code, and then parses the whole lot back into objects.
This is slow, and loses all information that cannot be remembered in an HTML string, such as JavaScript references, event handlers (all your onclicks will stop working) and form field contents (including file uploads).
You could add all the new HTML content to a temporary container instead, then move that using DOM methods to the destination:
var div= document.createElement('div');
div.innerHTML= text;
while (div.firstChild)
document.getElementById("labelContainer").appendChild(div.firstChild);
Or you can use DOM methods to create and add the nodes directly. In your case since the new nodes are so similar to the old ones, you could clone them:
function addLabel() {
var container= document.getElementById('labelContainer');
var tables= container.getElementsByTagName('table');
var n= tables.length;
var table= tables[0].cloneNode(true);
table.id= 'labelDiv'+n;
var inputs= table.getElementsByTagName('input');
inputs[0].id=inputs[0].name= 'label'+n;
inputs[1].id=inputs[1].name= 'browsetrainset'+n;
container.appendChild(table);
}
(Care: IE has some issues with changing field names with things like radio buttons though.)
If you want to be accessible without JavaScript (generally a good idea), the usual approach is to include the maximum number of entries you might, and use script to hide the ones that aren't in use.
If I remember correctly, it is not possible to programmatically set the filepsec associated with an <input type="file"> element, as this would constitute a security risk, by allowing malicious scripts to upload files that had not been specifically chosen by the user.
The only way to set the filespec is to browse to it from the web browser.