I've been playing with Selenium lately, trying to create tests for an IE only application. Things were progressing (though slowly as without the recorder plugin I had to resort to trial and error to try to find the appropriate element paths), but now I'm stuck with a problem related to popup menues.
Most of the application actions are triggered from a popup menu created with javascript window.createPopup() and I can't seem to find a way to send events to elements inside the popup.
Maybe I should be selecting the popup like I do for windows opened with window.open(...), which are working fine BTW. I tried assigning a name to the popup menu returned by createPopup() and treating it the same way I treat windows but that doesn't seem to be working.
Does anybody knows if this is supposed to work? Any help will be appreciated.
Thanks,
Unfortunately, no. window.createPopup isn't accessible to Selenium. Being an IE only feature it has really limited portability and generally isn't a best practice. I know that's of little consolation to you, because I assume your stuck with someone else's code that's used createPopup.
The real problem is that craeatePopup doesn't add anything to the DOM. Try opening a popup object and viewing it's source. You'll see this:
<html><body></body></html>
So there's nothing really there for Selenium to grab hold of.
What does the popup do for your application? You indicated it provides some navigation, can you just navigate to those pages directly?
if you know the name of the window you can do
selenium.click("elementToLaunchPopup");
selenium.waitForPopup("nameOfWindow",30000);
selenium.selectWindow("nameOfWindow");
// rest of your test
To get back to the main window you will need to selenium.selectWindow("null");
I am using selenium 2.0b3 with InternetExplorerDriver. I found something that do the trick.
In your js save a reference to the popup window.
var popUp= window.createPopup();
Then in your java code:
public Object executeJS(String code){
JavascriptExecutor js = (JavascriptExecutor) driver;
return js.executeScript(code);
}
WebElement popUp =(WebElement)
executeJS("return popUp.document.documentElement;");
This will give you a reference to the page and you can find elements normally.
Related
I've got a problem with script that works well on when I run it on current tab but when I try to use it on other widow using window.open it doesn't work. The simplified version of code looks like this:
var win = window.open("some_url");
var new_element = win.document.createElement('div');
new_element.textContent = "some text";
win.document.head.appendChild(new_element);
Im using chrome snippet tester in dev tools and it works perfectly fine when i run this stript on current window. I know it doesn't work in new widow because inspecting doesn't show any new elements. Does anybody know why it won't work? I have zero knowledge about the order of DOM creation and so on. Maybe I can't append to it until its already loaded?
After some digging I've finally got not a solution but an anwser. The reason why code did work on blank page but not on some real url's is because normally websites use Cross-site scripting blocks that are blocking such actions. So there was nothing wrong with the code. It was the site that was blocking it's execution.
Hello guys,
I have a strange problem with my ASP.NET 4.5 page. For some strange reason, my window.onbeforeunload function gets overwritten every time I load the page. Inside the debugger, I can clearly see that the right value is set in my head section, if I place a breakpoint there. However, after finishing the loading process of the site, the value changes to the following:
function (a){return typeof p!="undefined"&&(!a||p.event.triggered!==a.type)?p.event.dispatch.apply(h.elem,arguments):b}
I have no idea where this is coming from. This is my code from the head section of the page:
window.onbeforeunload = function (e) { return 'Do you really want to cancel?'; };
I'm using JQuery 2.1.3 as well as DevExpress 14.2 in my project. Any idea what could be responsible for this weird behavior?
Thanks in advance!
I actually found the answer where this is coming from thanks to #DavidTansey's hint. It's the Browser Link feature that was introduced in Visual Studio 2013. It looks like Browser Link uses some old jQuery library and overwrites various handlers.
So if you are having the same issue, please try to disable the feature (the menu is next to the browser selection in the tool bar). This should solve the problem.
I'm pretty sure that this problem wouldn't appear on a real server, because it would likely not use Browser Link.
I was looking into making Firefox addons, and I need some help.
Is it possible to edit an HTML page that is open in the browser with javascript?
For example:
User types in "google.com"
Addon is activated
Javascript changes contents of "google.com" to maybe say "Hello!" at the bottom.
Of course this isn't specifically what I want to do, but a push in the right direction on how to accomplish such a task would be great.
~Carpetfizz
From within a Firefox addon this is obviously possible as many extensions do this.
If you, however, simply want to modify the DOM and nothing else than I would recommend taking a look at greasemonkey. Loads of example scripts around to do this: http://userscripts.org/
And the added benefit, if written correctly they also work in Chrome and other browsers.
Yes, it is. You must find a tutorial about javascript DOM manipulation
I"m wondering if anyone can give me some insight into a really strange IE9 issue I've been struggling with.
I'm finishing up production of a site for work - it works well in ff/chrome/ie7/ie8 with no script errors.
On IE9 the last step of the application causes the entire tab to whitescreen with no script errors or warnings. (changing the document mode to ie8 will fix the problem but is obviously unsuitable for production)
Unfortunately the site pretty complex with a ton of ajax, and in-page scripts so I can't really post the relevant code easily. I'm more trying to figure out how to diagnose this.
I've checked the IE error logs and they are empty. Web developer tools tells me nothing. The site is not using any plugins (Flash/Silverlight, Ect. ) just javascript w/jQuery.
There is a PDF being displayed in an iframe around the step where it fails - but a nearly identical pdf is displayed in the previous step (using the same method) without problem. The code fails around a call to the jquery UI window but I can't seem to get the exact line.
If anyone has a clue how to try to diagnose this further I'd really appreciate it. I can keep hunting for the bug but I've never seen this kind of behavior before and just am not sure what I am looking for.
Thanks for all the input on this. Sorry I got completely overwhelmed by a few projects at once so I wasn't able to post updates on the debugging steps.
It took forever but I finally realized that everything was crashing when I closed the dialog containing the first PDF.
One of my helper functions was opening the dialog and automatically destroying the contents on close. Normally this works fine as I'm either removing a div containing the page fragment, or the iframe.
In this situation I had a page fragment loaded into the dialog which contained some buttons and the pdf iframe. I called the .remove() method on the parent element containing the iframe rather than the iframe itself. For some reason this seems to work fine in every other browser - but in IE9 it pretty much kills the page rendering without any warning or message.
I strongly suspect that the culprit is the adobe plugin but I'm not entirely sure.
Here is the fix-
Html:
<div id="container">
<iframe src="loremipsum.pdf"></iframe>
</div>
Javascript:
//Ruins my entire week
$("#container").remove();
//Works as the pdf is removed directly
$("#container").find("iframe").remove().end().remove();
I ran into the same issue on IE11 while trying to remove an iframe in a div with AngularJS. Removing the iframe first would just cause the same issue, so I navigated the iframe src to a new page (about:blank) first, then removed the div which worked. Hopefully this helps someone with a similar problem.
Pseudo-code below:
$ctrl.iframeUrl = 'about:blank'; // change the iframe url here
$timeout(function(){
$ctrl.removeIframe(); // remove the iframe here
});
As a thing to try - see what's in the IE9 DOM viewer after it whitescreens. There's a decent chance that most of the stuff is there and just not rendering properly (or having something else rendered over it). At the very least, knowing whether it's losing a ton of stuff out of the DOM or not should give you some useful data.
Is there any tool or addon which can be used for testing or identifying Javascript functions in real time (i.e. on click or some events )..
e.g. on a website, I want to know after clicking on a link, which all JS functions are being called/executed..I know sometimes it is stragightforward from the code, but in case it uses JS libraries like jQuery, the actual function call is made from otside..
How can I do that?
*I'll really appreciate if, alongwith the addon, you just write a short description as to where can I find the Javascript finction tracking in that **
Thank you.
Try Firebug. It's one of the most useful firefox addons. Grab it here:
http://getfirebug.com/
Dragonfly (Opera), or Firebug extension for Firefox, or any other good javascript debugger
See Visual Event. It is a bookmarklet that overlays element event handler information.
FireQuery is available as a firefox plugin which adds handler information inside of firebug.
Firebug includes a JavaScript profiler. Give it a try.
http://getfirebug.com/javascript
In Chrome, right click the page and choose Inspect element, go to the console, start javascripting! Choose the scripts tag to get debugger functionality.