Autofill date in textbox in geckofx - winforms

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";

Related

Flask and sqlite: Failing to insert values into the database

I have the following code in the main.py file. It appears to work in all instances, note when I print out user_details, it prints out the tuple: test,test,test (filled in to the form), so the post request is working. However, somehow, it is not being actually written to the database.
Main nature of error: The insertion is not taking place.
Can someone spot an error in my code?
#ADD COMMENT GET POST REQUEST FUNCTION
#app.route('/add',methods=['GET','POST'])
def addcomment():
if request.method=="GET":
return render_template('addcomment.html')
else:
user_details=(
request.form['title'],
request.form['name'],
request.form['comment']
)
#print(user_details)
insertcomment(user_details)
return render_template('addsuccess.html')
#INSERTING comments into the actual database
def insertcomment(user_details):
connie = sqlite3.connect(db_locale)
c=connie.cursor()
sql_insert_string='INSERT INTO comments (title, name, comment) VALUES (?,?,?)';
c.execute(sql_insert_string,user_details)
connie.commit
connie.close()
print(user_details)
def query_comments():
connie = sqlite3.connect(db_locale)
c=connie.cursor()
c.execute("""
SELECT * FROM comments
""")
userdata=c.fetchall()
return userdata
My suspicion is that there is something wrong with these lines (that is the second function)
insertcomment()
connie = sqlite3.connect(db_locale)
c=connie.cursor()
sql_insert_string='INSERT INTO comments (title, name, comment) VALUES (?,?,?)';
c.execute(sql_insert_string,user_details)
The def addcomment(): function works fine as far as I can see, rendering and returning the right html page on clicking submit.
On the html side, the only thing I can think of that MAY be causing an error is the order of the fields. In the database the fields are Name, Title, Comment (in that order), but in the HTML and the query, they are Title, Name, Comment (in that order specified).
For reference, the HTML file (the form that accepts that data) is below:
<div class="form-group">
<label for="exampleInputEmail1">Title (or catchy caption!)</label>
<input type="text" class="form-control" id="title" name="title" aria-describedby="emailHelp">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Name</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Add your amazing answer here:</label>
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
On the home page, the data is rendered as follows. I've had to switch the numbers around as you can see, as 2= title 1=name and 3 = comment
{% for user in user_data%}
<tr>
<th scope="row">{{user[0]}}</th>
<td>{{user[2]}}</td>
<td>{{user[1]}}</td>
<td>{{user[3]}}</td>
</tr>
{% endfor %}
Whether the above has anything to do with the error, I don't know (the order)...but I cannot think why.
Finally, here is the table populate .py file. You'll notice there is one extra field - date. Again, could this be a factor?
#populate database file
import sqlite3
db_locale='users.db'
connie=sqlite3.connect(db_locale)
c=connie.cursor() #use this to create commands
#creating a multi-line instruction
c.execute("""
INSERT INTO comments (name,title,comment,date_posted) VALUES
('Ruth Marvin','42','Yeah.Someone was going to say 42','20th July 2050'),
('Jonathan Peter','Meaning?','Surely we need to first define meaning','13th August 2050')
""")
connie.commit()
connie.close()
Can anyone explain why the data is not being POSTED/INSERTED into the database.
The error is in the function insertcomment(). You are missing the brackets with commit:
connie.commit
Just change to:
connie.commit()
which will save the changes to the database. Everything else looks fine including the database query. You are right in using a parameterised query.
sql_insert_string="INSERT INTO comments (title, name, comment) VALUES (%s,%s,%s)"
c.execute(sql_insert_string, user_details)
connie.commit()
this should work. Wrap your db operations into a try, except block to figure out whats wrong with your queries.
try:
sql_insert_string="INSERT INTO comments (title, name, comment) VALUES (%s,%s,%s)"
c.execute(sql_insert_string, user_details)
connie.commit()
except Exception as e:
print(e)
You need to format your SQL insertion string using Python's format() function from the standard library.
Your code:
sql_insert_string='INSERT INTO comments (title, name, comment) VALUES (?,?,?)';
Should be like this:
sql_insert_string='INSERT INTO comments (title, name, comment) VALUES ({}, {}, {})'.format(user_details[0], user_details[1], user_details[2])
Then on your c.execute line just pass sql_insert_string as a parameter. Also, I've found that the flask-sqlalchemy module saves countless headaches, but kudos to you for taking the time to learn SQL and coding it like this.

iMacros: Script: Split array on

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];")

Chaining an element using css containing text and accessing an associated field

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");
}
}

Using text input as filter option

I struggle with the usage of the filter. I have an input field that i want to use as a filter option.
The array looks like this:
$scope.Examples=[
{
name:'Dolly',
place:'roof',
description:'Dolly is a friend of Mike.'
},
{
name:'Mike',
place:'cellar',
decription:'Mike doesn't like the roof.'
},];
$scope.Search="";
The Input:
<input ng-model="Search"
type="text"
placeholder="type something here">
And the ng-repeat:
<tr ng-repeat="something in Examples |filter:Search">
{{something.name}}
</tr>
Now, if i type in "Dolly", he shows me Dolly quite as planned. But if i type in "Mike" the output is Dolly and Mike, because i used the word Mike in the description for Dolly. The same for typing in "roof".
I tried to use
<ng-repeat="something in Examples |filter:{name:'Search'}">
but in that case it simply don't work and there is no output. What i want to do is restrict the filter to 'name' only. Maybe someone have a suggestion how i could make it work.
I'm thankful for every advice.
If you write {name:'Search'} instead of {name:Search}, it means that you keep any string which contains the 'Search' string
Try this :
<ng-repeat="something in Examples |filter:{name:Search}">

retain value of input type file in a jsp file while being dynamically generated

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.

Resources