w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
testing DOM elements with phantomjs/casperjs
Have you tried any of the waitFor functions. You could try something like this: casper.test.begin('Main page test', 2, function suite(test) { casper.start('http://xxx.yyy.zzz/', function() { test.assertTitle('My page name', 'page title is set correctly'); }); casper.waitFor(function check() { return this.evaluate(function() { return $('loading label').is('hidden'); }); }, function then() { // step to execute when check() is ok test.assertExists('#tabsListArea', 'tabs area is found'); }, function timeout() { // step to execute if check has failed this.echo("Timeout: page did not load in time...").exit(); }); casper.run(function() { test.done(); }); }); You could then play around with the waitT

Categories : Javascript

phantomjs/casperjs count DOM elements
If you can use jquery its fairly simple: var count = $('div.classname').length; Found an SO Post that seems to explain using jquery with casperjs, I have no experience with casperjs so I can't help much there.

Categories : Javascript

Finding multiple elements
In case someone looks for this in the future, I got it to work: findElements(By.className("someclass")).then(function(elements_arr){ console.log(elements_arr.length); }); According to their source code, findElements returns a promise https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#803

Categories : Javascript

Finding Elements in Linq to XML
Following code give you the account number of the matching element, members.Where(x=> x.Element("AccountName").Value==validationName).Select(x=> x.Element("AccountNumber").Value).FirstOrDefault();

Categories : C#

Finding and Updating PHP 2D Array Elements
Is there a reason you're using a multidimensional array instead of just an associative? You're not iterating over any indexes because there aren't any present within the aggregated array format. The correct format should be : Multidimension : $mailMessage = array( 0 => array( 'mailNumber' => $mailCount, 'mailID' => $mailID, 'mailDate' => $mailDate, 'mailSender' => $mailSender, 'mailSenderName' => null, 'mailMsg' => null ) ); Associative : $mailMessage = array( 'mailNumber' => $mailCount, 'mailID' => $mailID, 'mailDate' => $mailDate, 'mailSender' => $mailSender, 'mailSenderName' => null, 'mailMsg' => null );

Categories : PHP

Finding the number of form elements
As Amine hinted, use the :input selector: $(':input').length

Categories : Jquery

Finding Out Which Elements Are in the Viewport in Dojo
Thanks to a few pointers from a friend, I was able to put together a functional solution to this question. Assuming all the divs are within another div with the id articles, when the user scrolls the bottom of the element at least 50px into the viewport, I then apply a "read" class to the element. posts = dojo.query("#articles > div"); dojo.connect(window, 'onscroll', function(){ var vs = win.getBox(); var output; var readCount; for (var i = 0; i < posts.length; i++) { var includeScroll = false; var locInfo = domGeom.position(posts[i], includeScroll) var fullyOnScreen = locInfo.y + locInfo.h + 50; if ((fullyOnScreen > 0) && (fullyOnScreen < vs.h)) { //Apply "read"

Categories : Ajax

Finding consecutive elements in a vector
Due to the limitations of std::adjacent_find you can't use it quite the way you want to. However it can still be useful. What you can do is to iterate over the collection, and use std::adjacent_find in a loop, with the last returned iterator (or your outer loop iterator for the first call) until it returns end. Then you will have a complete set of consecutive elements. Then continue the outer loop from where the last call to std::adjacent_find returned a non-end iterator.

Categories : C++

Finding the number of elements between i and j in an integer array in o(1)
Dim result() as integer Dim C(1000) as integer Dim Buff() as integer Dim i as integer=50 dim j as integer=450 for count =0 to c.count-1 if c(count)>i and c(count)<j then dim length as integer=buff.count-1 redim result(lenght+1) for buffcount=0 to buff.count result(buffcount)=buff(buffcount) next result(result.count-1)=c(count) redim buff(result.lenght-1) buff=result end if next

Categories : Arrays

Finding common elements in two arrays of different size
Assuming you can have "holes" in your matched sequence (A = [1,3,2] AND B = [1,4,2] Then MatchSet = {1,2}) Maybe I am wrong but you could try this pseudo code: i <- 0; j <- 0; jHit <- -1 matchSet <- Empty While i < Length(A) AND j < Length(B): If A[i] == B[j] Then matchSet.add(A[i]) i <- i+1 jHit <- j End If j <- j+1 If j == Length(B) Then i <- i+1 j <- jHit+1 End If End Loop The first index (i) points to the next element of A not found in B whereas (j) is used to look for the next element of B (after the last element found in A). This yould give you a time complexity of O(mN) and space usage of O(N). Here you have an implementation in Python: def match(A,B): i = 0 j = 0 jHit = -

Categories : Arrays

Efficient method for finding elements in MATLAB matrix
Try doing something like this: for i = 1:1000 x = (a >= 0.5); x = (x < 0.6); end I found it to be faster than: for i = 1:1000 x = (a >= 0.5 & a < 0.6); end by about 4 seconds: Elapsed time is 0.985001 seconds. (first one) Elapsed time is 4.888243 seconds. (second one) I think the reason for your slowing is the element wise & operation.

Categories : Matlab

ShadowRoot not finding elements inside template repeat in Polymer
Try putting the query into a Timer.run. Timer.run(() { print("timer"); var charDivs = this.shadowRoot.queryAll('.char'); print("charsDiv: ${charDivs.length}"); }); Then, when I populate the chars="{{someList}}" attribute with a list, eg: ['d','e','f'], I get the full set (ie, length=6) returned. Here's a gist demonstrating the complete code: https://gist.github.com/chrisbu/6488370

Categories : Dart

Finding the full height of the content of a page/document that can have absolutely positioned elements
If this can give you some help: alert($('body')[0].scrollHeight); also this command give me the same value: alert($('body').context.height); I tryed with this script but it should be improved cause it gives different result with different browser. var k=0; var off = document.documentElement.offsetHeight; $('#but').click(function(){ //let's go faster here (first 3 before the user touch something $('html body').scrollTop(9999999); //best scroll var k=$('html body').scrollTop();//getrealscroll $('html body').scrollTop(0);//backscrollto0 alert(off+k);//the height }); I would like to suggest you a script that, considering if there is absolute element, find the height: <button id="but">Scan me</button> var maxhabs = 0; var maxhrel = 0; var realh = 0; va

Categories : Javascript

g3d.utils not (anymore) available?
The new 3D API (which is what Xoppa has been working on) is only available in post-0.9.8 builds, which at the moment is the "nightly" builds: http://libgdx.badlogicgames.com/download.html

Categories : Java

Django cannot import name utils
Please ensure both the project path and site-packages for your virtual environment are added to your mod_wsgi configuration. WSGIPythonPath /path/to/mysite.com:/path/to/your/venv/lib/python2.X/site-packages Django docs for deploying using mod_wsgi and a virtualenv

Categories : Django

Using android-maps-utils with ADT
First of all, download it to your computer. If you don't use git, just press Download ZIP in the bottom right corner. Then you have some options (from the easist): Copy res and src folders from the library folder directly to your project. This should be ok as long as you keep the license info. Copy some project.properties into library folder. Now the library project will be importable in Eclipse. Use Android Studio, which has support for Gradle.

Categories : Android

UI not updating with ko.utils.arrayFilter
Your selectThing shouldn't write to ko.computed. They are supposed to be read only (unless specified otherwise). So what your function does is overwriting var CertificateDetailsToShow with static data so it's not observable anymore and therefore knockout doesn't take it under consideration when updating UI. That's how you missed the concept and answers your question. To fix this either make var CertificateDetailsToShow an ko.observable and in selectThing just put new value in it: CertificateDetailsToShow( certificateID ) or as you already saving it in isSelected(row.lwCertID) use it in your ko.computed by defining filter (and don't overwrite it): var filter = isSelected() return ko.utils.arrayFilter(CertificateDetails(), function (CertD) { return CertD.CertificateID == filte

Categories : Knockout Js

Java Logging (utils) probelm with Levels
I haven't used Java Util Logging before but base on my experience in Log4J/SLF4J, your way of using JUL seems strange. We don't setup the handler and logger's level every time we get the logger. Normally it is one-time setup before the application run. So that JUL already have the logger hierarchy setup correctly, and you are simply getting the logger you want to use and do your logging. The way you do the setup is going to cause big trouble too, because you will add a new ConsoleHandler every time you get the same logger. That means, if you get it 10 times, the logger you got from the 10th time, each logging will cause 10 message to display on screen. Come back to your problem, I believe the root logger in JUL is setup with a ConsoleHandler by default. That means, you don't really

Categories : Java

stringTrim Knockout Utils not working when bundling
The issue is that ko.utils.stringTrim is not currently identified as an exported method, so when Knockout is minified using Google's Closure Compiler the name of this method gets minified. In the release build you end up using the minified file rather than the debug version. The logic for stringTrim in Knockout is: stringTrim: function (string) { return string === null || string === undefined ? '' : string.trim ? string.trim() : string.toString().replace(/^[sxa0]+|[sxa0]+$/g, ''); } You could choose to add it to your project. If you are only supporting newer browsers (IE9+), then you could just use string.trim(), otherwise you could potentially add it in older browsers as described here: https://developer.mozilla.org/en-US/d

Categories : Asp Net Mvc

Android & OpenCV : Utils.bitmapToMat crashes
oh, you cannot use any opencv - related code, until the manager finished loading ;) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { if (status == LoaderCallbackInterface.SUCCESS ) { // now we can call opencv code ! Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cmc7); Mat myMat = new Mat(); Utils.bitmapToMat(mBitmap, myMat); } else { super.onManagerConnected(status); } } }; @Override public void onResume() {; super.onResume(); OpenCVLoader.initAsy

Categories : Android

django.db.utils.DatabaseError: out of shared memory
I have had a quick google and there are a couple of resources to look at: postgresql: out of shared memory? http://www.databasesoup.com/2012/06/postgresqlconf-maxlockspertransaction.html This quotes is taken from http://www.postgresql.org/docs/9.1/static/runtime-config-locks.html max_locks_per_transaction (integer) The shared lock table tracks locks on max_locks_per_transaction * (max_connections + max_prepared_transactions) objects (e.g., tables); hence, no more than this many distinct objects can be locked at any one time. This parameter controls the average number of object locks allocated for each transaction; individual transactions can lock more objects as long as the locks of all transactions fit in the lock table. This is not the number of rows that can be lo

Categories : Django

Finding Relationship between elements in a Tree structure, where no initial relationship
You can build a forest initially, and when you have a connection, join trees in the forest. If the hirerchy is indeed tree-like, by doing so you will end up with a tree - as expected. Regarding "no binary tree" - no problem, use a generalized tree. The implementation (in java-like language) would be something like: class Node<Key> { Node<Key> father; final Key root; final List<Node<Key>> sons = new LinkedList<Node<Key>>(); //constructor, methods and more fields if needed } One more thing - I'll add an extra dictionary (hash based/ tree based) to map from the employee/manager key to the node object representing this employee. If using the above data structure, the map will be something like Map<Key, Node<Key>>.

Categories : Algorithm

IntegrityError #1062 in django.db.utils - Duplicate entry for key 2
Try and insert data using the error handle mechanism:- from django.db.utils import DatabaseError,IntegrityError Then do something like this to prevent your python script to stop :- try: #write code to execute query here except IntegrityError: #write code to handle exception here(example creating a log)

Categories : Python

Code organisation and differentiation between tools and utils packages
Both "tools" and "utils" are bad names for classes/packages. It is not object oriented. It is a way of saying, "I don't know what to name this thing so I'll just give it a generic name". What you should do is figure out what these tools/utils are really doing and name them appropriately.

Categories : Java

Finding k-largest elements of a very large file (while k is very LARGE)
Use randomised selection to find the kth largest element in the file. You can do this in linearly many passes over the input as long as it's not too ridiculously many times larger than memory. Then just dump out everything that's at least as large as it.

Categories : Algorithm

Array data push inside knockout utils foreach
This makes no sense to me : item.push(self._isVisible); I think what you want to do is more something like that : ko.utils.arrayForEach(data.results, function (item) { item._isVisible = true; }); Could you explain what want to do ?

Categories : Javascript

Nested form parent object : got Rack::Utils::KeySpaceConstrainedParams
I encountered the same error then I renamed the name of the checkbox array to something else other than the name of the model. It worked. For example you have @dashboard_banners as your model then you call your checkbox dashboard_banners[]. I think that causes the error. Name it to something else like d_banner[] then fetch ii in the controller as params[:d_banner]. Then you can loop it in the controller or do anything that you like.

Categories : Ruby On Rails

Native function call in testcase using gwt-test-utils causes UnsatisfiedLinkError
You have to patch the native alrt() method by writing a custom Patcher. It's explained here : https://github.com/gwt-test-utils/gwt-test-utils/wiki/Writing-custom-Patchers

Categories : Java

org.sonar.api.utils.SonarException: Validation of project reactor failed
Apparently, your Gradle project group or name contains a whitespace. This value becomes part of the default value for the Sonar project key, which must not contain whitespace. To fix the problem, you can either reconfigure the Gradle project group or name (it's safer not to have a whitespace in there anyway), or reconfigure the Sonar project key for the project that applies the sonar-runner plugin. The latter could look like this: sonarProperties { property "sonar.projectKey", "foo:shared" } If the offender is the Gradle project name (rather than the group), you may have to reconfigure "sonar.projectName" as well.

Categories : Gradle

How to run a set of tasks in parallel and wait until all of them are finished with java concurrency utils?
You can use ExecutorCompletionService - it allows you to get Futures in the order they are completed. You will still have a tiny while loop, and the code you want to invoke after everything is completed will be after the loop. I think that should be ok.

Categories : Java

Finding common elements from two lists of lists
Convert the innermost lists of b into a set(s), and then iterate over a to check whether any item in a exist in s or not. tot_items_b = sum(1 for x in b for y in x) #total items in b Sets provide an O(1) lookup, so the overall complexity is going to be : O(max(len(a), tot_items_b)) def func(a, b): #sets can't contain mutable items, so convert lists to tuple while storing s = set(tuple(y) for x in b for y in x) #s is set([(41, 2, 34), (98, 23, 56), (42, 25, 64),...]) return any(tuple(item) in s for item in a) Demo: >>> a = [[1, 2, 3], [4, 5, 6], [4, 2, 3]] >>> b = [[[11, 22, 3], [12, 34, 6], [41, 2, 34], [198, 213, 536], [1198, 1123, 1156]], [[11, 22, 3], [42, 25, 64], [43, 45, 23]], [[3, 532, 23], [4, 5, 6], [98, 23, 56], [918, 231, 526]]] >>&g

Categories : Python

For Loop in CasperJS
This may be a stupid question, but are you firing the run() function? I've forgotten to include that which caused my program to just hang, generally it's the only reason I've seen for it to hang without error.

Categories : Javascript

How Do I use jQuery in CasperJS?
You have evaluate the jQuery code in the browser context using casper.evaluate execute code as if you were using the browser console. var nameCount = this.evaluate(function() { var names = $('span.author-name') return names.length; }); this.echo(nameCount);

Categories : Javascript

How to set a cookie in casperJS
Probably, the page has not received the cookie. You can try using the same code in load.started event listener. Also, add a evaluate script to check the existence of the cookie on each stage of the page load. That might help.

Categories : Javascript

CasperJS HTTP Authentication
I believe you need to call casper.setHttpAuth() before you load the page. It also looks like you forgot to call casper.exit() at the end of casper.run(). var x = require('casper').selectXPath; var casper = require('casper').create({ verbose: false, logLevel: 'debug' }); casper.options.viewportSize = {width: 1366, height: 667}; casper.start(); casper.setHttpAuth('here_i_type_username', 'here_password'); casper.thenOpen('https://mysite.com/a/dashboard', function() { this.test.assertUrlMatch(/^https://mysite.com/a/dashboard$/); }); casper.run(function() { this.test.renderResults(true); this.exit(); });

Categories : Testing

Iterating over a grid with CasperJS
The approach is correct but evaluate is sandboxed. In addition, the arguments and the return value to the evaluate function must be a simple primitive object but if it can be serialized via JSON, then it is fine. Closures, functions, DOM nodes, etc. will not work! Instead of returning wanted object, returns a serialized version of wanted object using JSON.stringify()

Categories : Javascript

Removing a DOM element using CasperJS
For execute javascript code from CasperJS, You have to use evaluate() method The evaluate() method as a gate between the CasperJS environment and the one of the page you have opened; everytime you pass a closure to evaluate(), you're entering the page and execute code as if you were using the browser console. Your code should be something like this: var casper = require('casper').create(); casper.start('http://pageurl.com/XYZ', function() { if (this.exists('.content-meta')) { this.echo('found .content-meta', 'INFO'); //evaluates an expression in the current page DOM context. this.evaluate(function(){ //delete div 'content-meta' $('.content-meta').remove(); }); this.then(function(){ this.captureSelector('result

Categories : Javascript

Binary base64encode at CasperJS
You can certainly use native js method like btoa() and atob() . Here is a very basic phantomjs script : var fs = require('fs'); var filedata = fs.read('thefilehere'); var res = btoa(filedata); console.log(res); phantom.exit(); Base64 encoding/decoding is not so complex and you can easily find js function such as this one.

Categories : Javascript

How to increase the timeout in CasperJS
As said here, The signature is waitFor(Function testFx[, Function then, Function onTimeout, Number timeout]) So, there is an additionnal argument to specify the timeout. casper.waitFor(function check() { //... }); }, function then() { //... }, function timeout() { //... }, TIMEOUT_IN_MS);

Categories : Javascript

casperjs, might need another click method?
Not entirely sure if this is what you want, but you can get the tab based on the tabindex attribute with: casper.click("a[tabindex='6']"); Edit: Hack I threw together based on your comment below: casper.thenEvaluate(function() { var attr = document.querySelector('img[alt="New Search"]').parentNode.getAttribute('tabindex'); __utils__.click('a[tabindex="' + attr + '"]'); }); casper.thenEvaluate() allows you to execute javascript on the remote page. __utils__ is injected into each page loaded as an extra set of functions that you can use.

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.