Access DOM from capybara-webkit #execute_script? - ruby-on-rails

So I'm trying to test that the jQueryUI sortable library triggers an ajax request and I haven't been successful at triggering it, I've tried this with the jquery.simulate.drag-sortable.js library, but to no avail. I've also tried it with the execute script function, also to no avail. I am trying to manually trigger the sortable deactivate event because jQuery.trigger() doesn't seem to work with it even in the browser. The script that is executed is $sortable.sortable("option", "deactivate")(event, ui) with event and ui properly injected, this code works when I enter it directly into the browser.
The problem seems to stem from not being able to access the DOM. When I enable the debug mode on the driver the error is TypeError: '[object Object]' is not a function (evaluating '$sortable.sortable("option", "deactivate")(event, ui)'). Digging a little deeper reveals that the Javascript driver can't access DOM nodes within #execute_javascript. When I enter console.log(document.getElementById('sortable')); The response is 'null'.
Any thoughts on how to trigger the jQueryUI sortable function with the deactivate event using capybara-webkit?

Related

Can you use AddEventListener with CEF4Delphi?

I am using Delphi XE2 and Chromium CEF4Delphi. I am trying to use a web page via the TChromiumWindow component and would like to detect when an element is selected / clicked.
I saw this post..
Delphi Chromium - launch a command in Delphi application when button in web page is clicked by user
Unfortunately, I cant find the function AddEventListenerProc in the CEF4Delphi library. Neither can I find an alternative way to monitor a button / element click.
I would like to use the TChromiumWindow component to act as a "fron-end" to my app and would like to monitor user button clicks etc.
Can anyone help please ? I did try the developer forum but I dont see much activity there and was unable to register.
Many thanks..
The DCEF3 project has a group here : https://groups.google.com/forum/#!forum/delphichromiumembedded
But the CEF4Delphi and OldCEF4Delphi projects have a developers forum here :
https://www.briskbard.com/forum/
That forum has new posts almost every day and I try to answer them as soon as I can, usually in less than 24 hours.
If you have problems creating an account just send me a message and I'll activate your account manually.
The link you posted is very old and many things have changed in CEF since 2012.
There are several ways to detect when a HTML element has been selected, clicked, etc.
You can use a JavaScript event like "onclick" that calls a custom JavaScript extension. That extension would send a process message to the browser process to notify that the user clicked that element.
You can also use the GlobalCEFApp.OnFocusedNodeChanged that is triggered when an HTML element has been focused. This event is executed in the "render" process so you will also need to send a process message to the main browser process that the focused element has changed.
Use the JSRTTIExtension or the JSExtension demos as a template for your app.
They show you how to set a "mouseover" event that calls the "myextension.mouseover" function defined in a custom JS extension. The myextension.mouseover function executes Delphi code and sends a process message to the main browser process with some HTML information that is shown in the status bar.
They also have an example for a "MutationObserver" that calls a generic "myextension.sendresulttobrowser" function in the JS extension that sends the "value" attribute to the browser process.
Build the demo and right-click on the web page when it's fully loaded. Then select the "Set mouseover event" or "Add mutation observer" options to test what I described.

Getting [error] Element css=input.logon_button.logon_button_hover not found in Selenium IDE

I am using Selenium IDE 2.9.0 firefox addon
Trying automate the URL testing
But I get the following error when I try to automate the login,
[error] Element css=input.logon_button.logon_button_hover not found
Looks to me like it's a variable element. The hover part may only show while you are hovering over the link, which you won't be when selenium is running. Rather that right clicking and using the command, or selecting from selenium, view the html for your page and find the element in the code while you aren't hovering over it, to ensure it isn't different.

Adobe Analytics event firing on every page

I'm using DTM to implement Adobe Analytics code on a single page app.
I have a link that we've set up successfully as an exit link and it fires as it should. If this matters, it opens in a new tab and we don't actually exit the website. However, any time we fire off any subsequent page views, we see the same event fired. Is there any way to fire off this event only when the link actually is clicked? I assume that because it's a one page app and the code isn't getting refreshed that is the reason it's on every subsequent page.
Using Adobe Analytics and DTM is frustrating with single page apps. What we do is clear all the variables that are set before each page view. We have a function that clears, props, evars, events, listVars, heir, pageName etc.
Please check witch version of s_code you are using, if you are using Appmeasurement or one of the last s_code versions please use clearkVars() function.
following code is a log from browser console with console responses:
s.events ="event1"
"event1"
s.linkTrackVars='events';
"events"
s.eVar1="value"
"value"
s.clearVars();
undefined
s.events
undefined
s.eVar1
undefined
you can fire this in custom code section (if your custom code section is set to fire after gui settings, or you can fire it as JavaScript 3rd party tag.

dojo AMD loader fails to download dependencies when it executed after page load

I am having consistency issues with the require function in dojo 1.8 when it is run after the page has loaded.
For instance, when I dynamicaly update a node on a webpage (portlets in this case) the content is received in JSON, which is sucessfully parsed and inserted inside the webpage. If it contains any script tags they are also successfully executed however, when the require function is called it sometimes, 50-60% of the time, fails to download its dependencies and reports a timeout error in the dojoloader. What's even more strange is that I see no requests initiated for the dependencies the loader reported as "timed out".
This only happens when it is called after the page has finished loading as I do not have any problem of this kind with scripts present at page load.
I've also noticed that when I purposefully make the server response slow (500ms sleep) it is never able to download the dependencies (The timeout is around 5 seconds so that shouldn't be a problem right?)
I've been experiencing this issue in Chrome, Firefox and IE9 (where it miserably always fails) and it is driving me mad as I cannot figure out why this is happening...
Thank you for any help provided.
A script tag generated by ASP MVC inside a declaratively set dijit/MenuItem was causing the problem.
<div data-dojo-type="dijit/MenuItem">
...
<script>
...
</script>
</div>
These two do not mix well together...

Firefox Extension Execution Priority

I couldn't find it anywhere on Mozilla's documentation. Suppose I code an extension that uses addEventListener on keypress. What is the execution priority if a webpage contains a JS code that calls addEventListener on keypress (or keydown) too? Is it guaranteed that my extension receives the event first?
The event first goes through a "capturing" phase, then a "bubbling" phase. If you use the capturing phase (by putting true as the last parameter to addEventListener) then your listener will get called before the one on the page, if the one on the page uses the bubbling phase. I guess if you don't know which way it works on the page, then you could just attach it to something out of reach of the page (like the browser object, or even gBrowser) and then you would be sure that yours goes first. See http://www.w3.org/TR/DOM-Level-3-Events/#event-flow

Resources