How to locate a web element using webdriver: - html

How can we locate the web element whose html is:
<div class="wgt dashlet-pane-flowing vbox h-stretch" style="flex: 8 8 0%;">
I have tried following:
driver.findElement(By.cssSelector(".wgt.dashlet-pane-flowing.vbox.h-stretch"));
driver.findElement(By.xpath("//div[#class='wgt dashlet-pane-flowing vbox h-stretch']"));
but it is failed with error unable to locate web element.
Any help will be great..
Thanks in advance.

Target div might be generated dynamically, so you can try to wait for its appearance in DOM:
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[#class='wgt dashlet-pane-flowing vbox h-stretch']")));

There are couple of reason you will get this error.
Element is in different frame (which I don't think is the case)
It's not loaded properly while you are trying to find out (which might be the case). Please read about explicit waits and it will resolve the issue. I don't like giving the direct answer but someone here will. :)
Your xpath is wrong. You can check that with firebug and xpather plugin of firefox.
You have landed on the wrong page (you can check that visually)

If everything is good and still you are not able to find element, try below xpath
//div[contains(#style,'flex: 8 8 0%')]"

Related

JWPlayer in Drupal has container ID starting with Numeric Character

Following up this question on SO, I am looking to change the default DIV container name that JWplayer provides to JWPlayer Div. The problem is that it starts with a numeric and that creates loading problems.
Is there a way, I can customize this JWPlayer ID ?
This is how it looks btw,
jwplayer('141ef7fe77391234fc105767808cc0a5').setup({"file":"my_video.mp4",
"width":"838","height":"383","controlbar":"none",
"modes":[{"type":"html5"},{"type":"flash","src":"http://path/jwplayer/player.swf"}]});
While you're at it, here is a quick solution to it.
Since this is a fix for Drupal JWPlayer Module, do the following:-
Go to jw_player module folder and open theme folder.
Open jw_player.tpl.php and add the following line on top (probably where PHP declaration starts).
$html_id = "myvideo". $html_id;
It kinda does the job but I am sure you guys have better solutions than this. Please feel free to comment.
Found a better solution
Don't do upper suggestion. Paste the following code in jw_player.module instead.
Find this line $variables['html_id'] = md5(rand()); (I guess line 308) and uncomment it before pasting the following code instead.
while(1) {
$variables['html_id'] = md5(rand());
if (ctype_alpha(substr($variables['html_id'], 0, 1))) {
//echo "First Digit is Alphabet";
break;
}
}
Thanks.

Using history.pushState in Angular results in "10 $digest() iterations reached. Aborting!" error

I'm trying to change the url in my app from "http://www.test.com/foo" to "http://www.test.com/bar+someVariable" (somevariable is a string that I recieve from an http request inside bar's controller) using history.pushState() . In my routes I enabled html5mode and everything works fine. I'm also using location.path() to switch between views and controllers as instructed in the docs. Now once the app switches view and controller I added history.pushState(null,null,"/bar"+somevariable) to "/bar"'s controller. Everything works and the url is updated but in the console I receive the "10 $digest() iterations reached. Aborting!" error. I suspect that activating the history.pushState function is somehow interfering with angular's $location or $route service.
What is the correct way to use history.pushState() within angular without receiving the $digest error?
By the way I'm using angular 1.0.3
Thanks ahead,
Gidon
Change the path with
$location.path('/newValue')
See: http://docs.angularjs.org/guide/dev_guide.services.$location
It is hard to know for sure without seeing the relevant source, but this is a common issue in older versions of IE (8 and 9 mostly I think). The solution that worked for me a few weeks ago when I encountered this (and may work for you if you're using IE) was changing my anchor tags in my navigation.
I had:
what fixed it:

Why always getting Nullpointer when doubleclicking link on XPage?

I have a difficult problem: I always get a Nullpointer exception on my webpace, when I
rapidly click on the same link. Or when I reload the page rapidly.
This is the error I get:
java.lang.NullPointerException
com.ibm.xsp.webapp.FacesServlet.acquireSyncToken(FacesServlet.java:285)
com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:161)
com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1281)
com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:847)
com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1265)
com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:653)
com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:476)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:341)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:297)
com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Question: Can someone explain in detail what this acquireSyncToken does? Maybe then I can find the bug...
In my XPages I use
sessionScope.get(key) // same with applicationScope
sessionScope.put(key, value) // same with applicationScope
a LOT ;)
I tried very much, e.g. to wrap my lookups within
synchronize(applicationScope){
// lookups and so on...
}
and stuff like that, but that only made it worse, so I removed the synchronize-stuff...
Environment:
Domino Server 8.5.3 FP1
XPages
testing on modern Browsers like FF, Chrome
MacOS / Win7
Architecture:
I have one BIG xPage, where I basically add some CustomControls and due to the current URL embed another XPage.
Inside the CustomControls and XPages I have more Custom Controls and I added some Views as Datasources and did the wildest things with "repeat controls" and SSJS inside Computed Fields.
The heavy-weight DB-Lookups are cached in the applicationScope.
For more Info, please ask!
Thanks in advance!
This is a known issue. IBM advises to downgrade from FP1 or FP2 to 8.5.3 or UP1.
See Dojo xhrGet with sync:false issue with xe:viewJsonLegacyService and Domino 8.5.3 SP1 or http://www-01.ibm.com/support/docview.wss?uid=swg1LO71603

FB.Canvas.setSize stopped working (today?)

This method seems to have stopped working.
App code was tested thoroughly last week and all was well. This morning...scrollbars are appearing on our page tab apps.
Example:
http://www.facebook.com/HondaPowersports/app_329359370439338
Very simple code on this page - it is all static HTML with just one FB method call:
window.fbAsyncInit = function() {
FB.Canvas.setSize({ width: 810, height: 975 });
}
Anyone else with this same problem? Any ideas?
According to the documentation (FB.Canvas.setSize):
Note: this method is only enabled when Canvas Height is set to "Settable (Default: 800px)" in the Developer App.
Has someone modified the settings of your Facebook app? If it's not configured as stated above then it stops working.
it seems to me it is deprecated and you have to use setAutoGrow... not sure , take a look :)
Related bug: http://developers.facebook.com/bugs/322561887802154

Can you take a "screenshot" of the page using Canvas?

I have a page where we're positioning a bunch of elements using CSS, and changing their "top and left" positions using JS.
I've had reports that these things have been misaligned, but a user has the motive to lie about this to "cheat", so I'm not exactly sure whether they're telling the truth. I'm trying to find a way to figure out whether they're lying or not, and to have some "proof".
I know that Canvas has a method to copy image information from an image element, or another canvas element (kind of a BitBlt operation).
Would it be possible to somehow, with Canvas (or with something else, Flash, whatever), take a "picture" of a piece of the page?
Again, I'm not trying to take information from an <image>. I'm trying to copy what the user sees, which is comprised of several HTML elements positioned absolutely (and I care most about those positions) and somehow upload that to the server.
I understand this can't be done, but maybe I'm missing something.
Any ideas?
Somebody asked a question earlier that's somewhat similar to this. Scroll to the bottom of Youtube and click the "Report a Bug" link. Google's Feedback Tool (Javascript driven), essentially does what you described. Judging by what I looked at of its code, it uses canvas and has a JavaScript-based JPEG encoder which builds a JPG image to send off to Google.
It would definitely be a lot of work, but I'm sure you could accomplish something similar.
If a commercial solution is an option, Check out SnapEngage.
Click on the "help" button in top-right to see it in action. Here is a screenshot:-
Setup is pretty straight-forward you just have to copy and paste a few lines of javascript code.
SnapEngage uses a Java Applet to take screenshots, Here is a blog post about how it works.
Yes you can See following demo
In below code I have define table inside body tag but when you run this code then it will display image snapshot.
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>test2</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"></script>
<script type="text/javascript" src="js/html2canvas.js?rev032"></script>
<script type="text/javascript">
$(document).ready(function() {
var target = $('body');
html2canvas(target, {
onrendered: function(canvas) {
var data = canvas.toDataURL();
alert(data);
document.body.innerHTML="<br/><br/><br/><br/><br/><br/><img src="+data+" />";
}
});
});
</script>
</head>
<body>
<h1>Testing</h1>
<h4>One column:</h4>
<table border="1">
<tr>
<td>100</td>
</tr>
</table>
</body>
html2canvas official Documentation:- http://html2canvas.hertzen.com/
To download html2canvas.js library you can use also if you unable to find from official link :-
https://github.com/niklasvh/html2canvas/downloads
[I am not responsible for this link :P :P :P]
You can use the element, that currently is only supported by Firefox.
background: -moz-element(#mysite);
Here #mysite is the element whose content is used as background
Open in Firefox: http://jsfiddle.net/qu2kz/3/
(tested on FF 27)
I don't think that you can do that. However, you could recursively fetch clientHeight, clientWidth, offsetTop and offsetLeft to determine the positions of all elements on the page and send it back to the server.
On Firefox, you can create an AddOn that uses canvas.drawWindow to draw web content to a canvas. https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas
I don't think there's a way to do that on WebKit at the moment.
It can be done, with some limitations. There are some techniques, and these are exactly how many extensions do screenshots. From your description it seems that you aren't looking for a generic, client side solution to be deployed, but just something that a user or some users could use and submit, so I guess using an extension would be fine.
Chrome:
I can point you to my opensource Chrome extension, Blipshot, that does exactly that:
https://github.com/folletto/Blipshot
Just to give some background:
You can do that, as far as I know, only from inside an extension, since it uses an internal function.
The function is chrome.tabs.captureVisibleTab and require access to the tabs from the manifest.
The function grabs only the visible part of the active tab, so if you need just that it's fine. If you need something more, than, you should have a look at the whole script, since it's quite tricky to get the full page screenshot until Google fixes Bug #45209.
Firefox:
In Firefox since 1.5 you can build extensions that use a custom extension of canvas, drawWindow, that is more powerful than the chrome.tabs.captureVisibleTab equivalent of Chrome. Some informations are here:
https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas