Casperjs sendKeys not working - web-scraping

I have this code to fill an input, I can get input attributes yet I can't set the value, could anybody help me either if it's with other library please.
var casper = require('casper').create();
casper.start();
casper
.then(function(){
console.log("Start:");
})
.thenOpen("https://alsea.interfactura.com/RegistroDocumento.aspx?opc=Starbucks")
.then(function(){
casper.sendKeys('#ctl00_Main_RegistroClienteTicket1_txtTienda', '12345');
this.echo(this.getElementAttribute('input[type="text"][id="ctl00_Main_RegistroClienteTicket1_txtTienda"]', 'value'));
});
casper.run();

The sendKeys() work in your case. If you do a screenshot you see that the form element is filled with the value you set:
var casper = require('casper').create();
casper.start("https://alsea.interfactura.com/RegistroDocumento.aspx?opc=Starbucks");
casper.then(function() {
casper.sendKeys('#ctl00_Main_RegistroClienteTicket1_txtTienda', '12345');
});
casper.then(function() {
casper.capture("test.png");
this.echo(this.getElementAttribute('input[type="text"][id="ctl00_Main_RegistroClienteTicket1_txtTienda"]', 'value'));
});
casper.run();
Probably the value is set is saved somewhere else on this site.

Related

Get Twitter Bloodhound Typeahead suggestions without opening dropdown

I am able to get all the Twitter Typeahead suggestions with the code below after user enters an input and the typeahead:render is called. I would like to hide the dropdown all the time and get the suggestions only in an array. Is there a way to achieve this since typeahead:render would probably require the dropdown be opened.
var bloodhoundData = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: localData
});
$('filter .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
source: bloodhoundData,
limit: 99999
}).on('typeahead:render', getSuggestions);
function getSuggestions() {
var suggestions = Array.prototype.slice.call(arguments, 1);
}
Since Bloodhound.js is a standalone library, you don't have to use typeahead with it. You could tie the input for bloodhound to an ordinary text input and examine the result of the get method.
Something like this might work, with q being the text from the input (borrowed from the NFL Teams example):
var myBloodhound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: function(obj) { return obj.name; },
local: localData
});
function getMyData(q, sync) {
myBloodhound.search(q, sync);
}
You can check out the bloodhound documentation here and the examples here.

Select User Broken in Concrete5.7 Composer

I am having issues with Concrete5's Build-In 'User' Property on the composer form for new pages. When clicking "Select User" the page navigates to http://website.com/ccm/system/dialogs/user/search. But that page is completely blank.
When you go into the attributes tab and click "Select User" under "Author" it also has the URL http://website.com/ccm/system/dialogs/user/search, but instead of reopening the page, it launches the user selector within the current page. This, I believe, is accomplished using the following JavaScript:
$(function() {
$("#ccm-user-selector-uID").dialog();
$("#ccm-user-selector-uID").on('click', function() {
var selector = $(this);
ConcreteEvent.unsubscribe('UserSearchDialogSelectUser.core');
ConcreteEvent.subscribe('UserSearchDialogSelectUser.core', function(e, data) {
var par = selector.parent().find('.ccm-summary-selected-item-label'),
pari = selector.parent().find('[name=uID]');
par.html(data.uName);
pari.val(data.uID);
e.stopPropagation();
jQuery.fn.dialog.closeTop();
});
ConcreteEvent.subscribe('UserSearchDialogAfterSelectUser', function(e) {
jQuery.fn.dialog.closeTop();
});
});
});
The 'User' option in the Composer has very similar JavaScript associated with it, replacing only the selectors.
$(function() {
$("#ccm-user-selector-ptComposer[13][user]").dialog();
$("#ccm-user-selector-ptComposer[13][user]").on('click', function() {
var selector = $(this);
ConcreteEvent.unsubscribe('UserSearchDialogSelectUser.core');
ConcreteEvent.subscribe('UserSearchDialogSelectUser.core', function(e, data) {
var par = selector.parent().find('.ccm-summary-selected-item-label'),
pari = selector.parent().find('[name=ptComposer[13][user]]');
par.html(data.uName);
pari.val(data.uID);
e.stopPropagation();
jQuery.fn.dialog.closeTop();
});
ConcreteEvent.subscribe('UserSearchDialogAfterSelectUser', function(e) {
jQuery.fn.dialog.closeTop();
});
});
});
I can't find anything that is keeping the functionality form working as expected on the Composer section, like it does on the Attributes section when creating a new page.
Has anyone else run into this or have any ideas on what might be the problem?
Turns out the issue was related to the two following lines:
$("#ccm-user-selector-ptComposer[13][user]").dialog();
$("#ccm-user-selector-ptComposer[13][user]").on('click', function() {
They aren't valid ID's and thus jQuery couldn't find them. A hacky solution to solve the issue was to replace lines 38 and 39 in concrete/src/Form/Service/Widget/UserSelector.php with
$("[id='ccm-user-selector-{$fieldName}']).dialog();
$("[id='ccm-user-selector-{$fieldName}']).on('click', function() {
Which allows for it to search out any elements that have an ID that matches that string.

How to correctly waitFor() a saveScreenShot() end of execution

Here is my full first working test:
var expect = require('chai').expect;
var assert = require('assert');
var webdriverjs = require('webdriverjs');
var client = {};
var webdriverOptions = {
desiredCapabilities: {
browserName: 'phantomjs'
},
logLevel: 'verbose'
};
describe('Test mysite', function(){
before(function() {
client = webdriverjs.remote( webdriverOptions );
client.init();
});
var selector = "#mybodybody";
it('should see the correct title', function(done) {
client.url('http://localhost/mysite/')
.getTitle( function(err, title){
expect(err).to.be.null;
assert.strictEqual(title, 'My title page' );
})
.waitFor( selector, 2000, function(){
client.saveScreenshot( "./ExtractScreen.png" );
})
.waitFor( selector, 7000, function(){ })
.call(done);
});
after(function(done) {
client.end(done);
});
});
Ok, it does not do much, but after working many hours to get the environement correctly setup, it passed. Now, the only way I got it working is by playing with the waitFor() method and adjust the delays. It works, but I still do not understand how to surely wait for a png file to be saved on disk. As I will deal with tests orders, I will eventually get hung up from the test script before securely save the file.
Now, How can I improve this screen save sequence and avoid loosing my screenshot ?
Since you are using chaning feature of webdriverjs it is wrong to use callback in waitFor function.
Function saveScreenshot is also chained. So the proper way would be the following:
it('should see the correct title', function(done) {
client.url('http://localhost/mysite/')
.getTitle( function(err, title){
expect(err).to.be.null;
assert.strictEqual(title, 'My title page' );
})
.waitFor( selector, 2000)
.saveScreenshot( "./ExtractScreen.png" )
.call(done);
});

Jquery Script Tag in Header

I know this is a really basic question, so forgive me. I have a script that works in a jfiddle, but I want to put it in my header and I can't figure out how to call it with a script tag and event handler(?).
Here's the script:
var retrieveValue = function(ev){
var $this = $(this),
val = $this.data('value');
if (val) {
$this.val(val);
}
},
hideValue = function(ev){
var $this = $(this);
$this.data('value', $this.val());
$this.val($this.val().replace(/^\d{5}/, '*****'));
};
$('#field_a7afui').focus(retrieveValue);
$('#field_a7afui').blur(hideValue);
$('#form_hv3hcs').submit(function(ev){
ev.preventDefault();
retrieveValue.call($('#field_a7afui')[0], ev);
alert($('#field_a7afui').val());
hideValue.call($('#field_a7afui')[0], ev);
});
Can someone please tell me what I need to put at the beginning and end of this just to throw it in my Wordpress header and call it a day?
Here's my jfiddle: http://jsfiddle.net/d5KaJ/40/
If that's what you were asking for...
into a script tag like:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script>
jQuery(function( $ ) {
// CODE HERE
} )();
</script>

meteor and textareas

Ok so I'm not sure why I can't render the code. First if I console.log users.content I get the content I want but I'm some how not able to pass it to a textarea so that it show's it...
Users = new Meteor.Collection("users");
if(Meteor.is_client){
Template.inputUser.code = function(){
var el = Users.find({name:"oscar"});
el.forEach(function(users){
console.log(users.content);
})
}
}
And then on my html template I have
<body>{{> inputUser}}</body>
<template name="inputUser">
<textarea>{{content}}</textarea>
</template>
And I would have a record on the db suck as so
if(Meteor.is_server)
Users.insert({name:"oscar",content:"hello world"})
Thanks for your help guys.
Firstly your method Template.inputUser.code should return something, you should also note that it wouldn't be called with that template either as it needs a {{code}} call in it rather than {{content}}
The second point is database contents are not always available if you have disabled the autopublish package, if so check out using publish(in the server code) and subscribe(in the client code): http://docs.meteor.com/#meteor_subscribe you can use this to check when the client has all the data to display. Something like:
Meteor.subscribe('allusers', function() {
Template.inputUser.code = function(){
var user = Users.findOne({name:"oscar"});
return user.content;
}
});
...
Meteor.publish('allusers', function() {
return Users.find();
});

Resources