I have a Watir code that uses Phantomjs as headless browser. I'm trying to fill a form on website using this code (because Phantomjs doesn't show modal on simple click (browser.link(id: 'choise-sity').click)):
require 'watir'
browser = Watir::Browser.new :phantomjs
browser.goto 'http://sales.ubrr.ru/open'
browser.execute_script(" $('#modalCityChoise').show();$('#modalCityChoise').css({'opacity':'1', 'top':'0'})")
browser.link(text: 'Архангельск').click
browser.screenshot.save 'a.png'
Current code does show modal, but I'm unable to click links there after.
My question is: is there an easier way to deal with modals in PhantomJS - they said they added support to modals? Or how to deal with this particular example by javascript injection?
edit: I managed to deal with this modal just by changing a value of hidden input browser.execute_script(" $('#OpenBkiForm_city_code').val('4600000100000') ") - but question still lingers.
I misinterpreted the issue - modals were managed correctly by Phantomjs, but I couldn't prove it because at the time of my screenshoting they were only beginning to fade in, which I haven't thought of.
The real issue was that I couldn't press the button in modal window. Turns out that was because of the window size - even when screenshots captured the button, it wasn't really accessible to Watir somehow. This resolved the whole issue:
$browser.driver.manage.window.maximize
Modals can be implemented differently. Sometimes they are animated which makes it necessary to wait until they are fully visible to then work on them further.
In your case you can use Wait:until:
browser.goto 'http://sales.ubrr.ru/open'
Watir::Wait.until { browser.a(:id => "modalCityChoise").visible? }
browser.link(text: 'Архангельск').click
browser.screenshot.save 'a.png'
Related
In our project, we need to use custom electron dialog windows, that have really fast opening time.
I tried the dialog module (in electron), but there's no way to edit it, although the time it takes to open the window is really fast.
Then, I made a modal window (using BrowserWindow) and made it act as a dialog when needed. This worked in a way as we were able to customize it however we want. But, the major issue is that it takes about 3-4 seconds to open a new modal window (worse if PC's performance is bad). This time consumption is causing a lot of issues as we have parts in the project where the user needs to notified instantly (errors and confirmations).
As another solution, I started creating a modal window at a very initial stage, then hide it and show it to the user (with updated contents using React states and props) whenever needed. This worked, however, since the application is already quite heavy, adding and keeping another Electron window open since the beginning is consuming a lot of memory.
I have used multiple packages as well, but all have the same time issue.
As of now, I have tried these solutions but all have bad parts that we are trying to majorly avoid.
I am trying to achieve the best possible way to handle these windows, which would be: opens really fast (<1s), is custom and less memory consumption.
Have I exhausted all my options? Or, is there any other way I can go about this problem.
Any help would be appreciated.
I'm writing some automated test scripts using Python (2.7) with Selenium RC (2.42.1) for a page that contains multiple tinymce controls (2 to be precise). The code that I've been using up to date looks like the following:
sel.focus( field_values[ id_value ] + "_ifr" )
sel.get_eval( "window.parent.tinyMCE.activeEditor.setContent('<p>" +
field_values[ test_data ] + "</p>');" )
To date, this code has worked fine for me, but after a recent build, I have been having issues when there are multiple copies of the tinymce control on the page. The setContent() function seems to always want to send the text to the second tinymce control, regardless of which ID I set the focus() to. And as a wonderful caveat, if I shrink my window frame so only the first tinymce control is visible on the screen, then only the first tinymce control gets sent any text.
My going theory right now is that the .activeEditor is not pointing to the right tinymce control when I set my content. It seems to always point to the last visible tinymce that it sees on the screen so I'm trying to find a way to force the focus to the appropriate tinymce control.
My question is, is there a better way to force the focus to the correct tinymce control using Python Selenium? I've tried using sel.click("tinymce") and sel.type_keys("tinymce","") after setting the focus(), but they don't seem to work.
I confirmed with the development team that no changes were made to the tinymce control, and I'm using the same Selenium RC version as always.
And I don't know if this will help, but there has been a push to move our automated testing over to a C# framework. We had the same issue as with the Python code, but we came up with a solution for that:
driver.SwitchTo().Frame(iWeb);
// This was added to ensure the tinymce control edit area has focus. This is necessary for pages that have multiple tinymce controls.
IWebElement body = driver.FindElement( By.TagName( "body" ) );
body.SendKeys( "" );
driver.Execute("window.parent.tinyMCE.activeEditor.setContent('" + Test_Data + "');");
driver.SwitchTo().DefaultContent();
I want to be able to do the same thing, but with the Python code.
I finally found the reason why I could no longer handle multiple instances of TinyMCE controls on the same page. I recently had to rebuild my machine due to hardware problems, and in the process, I updated my Firefox browser to the latest ESR release (24.7.0). I rolled back to v24.2.0 with no issues. It seems there must have been a security update that was causing the unusual behaviour with my automated code. I'm still researching what updates were made and if it's actually possible to write to multiple TinyMCE's with the latest ESR version of Firefox.
I have just started using ShareThis Widget to help handle social media integration with one of our sites. While the functionality is great, I feel I lose a lot of the capabilities I have if I were to code each item by hand, such as the ability to control the size of the windows opened by clicking a 'share' functionality.
While their site shows basic functions you can add to the buttons (url, etc) I am looking to customize the feel such that when a button is clicked, I can control the size of that window or even possibly open in an existing colorbox snippet.
Has anybody had luck with this before? When I try to control via javascript function it just seems to get overwritten or ignored.
You'd need to unbind their events and handle them all yourself. It probably isn't a good idea, as your code will be at the mercy of their implementation.
I am not sure if your question is resolved, but you will need to add as following inside JS.
popup: 'true'
The same is on their Support Page
Here's the thing
I have this master page, and in one of its slave pages there's a couple of Excel report generators, which, when retrieving the data, they take quite an awefull time because of the ammount of the data.
Well, i'm using a simplemodal windows to show a little gif to keep the user entertained. The thing is, i want this modal to close once its done doing the work
I can close it with the ESC key, but i want it to close by itself once its done working. I already tried with this code
SimpleModal breaks ASP.Net Postbacks
but it didnt worked, maybe its cuz i'm creating an excel file from a gridview, and its writting the scripr to another buffer.
I'm thinking on having close button on the modal once the whole thing its finished, but i'd rather have it close by itself
Any idea on how i can accomplish this will be pretty much appreciated
While I can't provide much help with SimpleModal, maybe you shouldn't use a modal dialog to show a loading/progress icon. I would suggest taking a look at spin.js:
http://fgnass.github.com/spin.js/
This probably makes a little more sense for your use case, and is pretty easy to use.
Good luck!
Try appending to the .NET form, this fixes some issues with jQuery's dialog so it may help.
$("#sample").modal({
opacity:80,
overlayCss: {backgroundColor:"#fff"}
}).parent().appendTo("form");
On the "work is done", you can programatically close the dialog using:
$.modal.close();
Well, i didnt wanted to use a popup windows, but given that to create a Excel file from a gridview needs to write the html of the gridview on the buffer and execute it, it was never reaching the part where the javascript was to be written and executed, so, no other choise than send the dataSet over a Session variable into a popup windows which generate the excel file, so having somehting like a parallel work
I had a pretty ugly issue with IE8, my save dialog wasn't appearing, it worked on IE6 and IE7, as well with opera, firefox and chrome, but IE was giving a issue. Found there's a security option which that didnt allowed the save dialog to appear. For any one having a similar issue, its on Internet option -> Security -> Custom Level... -> Downloas -> Automatic Prompting for file downloads -> Need to be "Enabled"
Any way, thanks for tha help, hope this info also helps someone else!
Sorry for the title.....bit difficult to word what I really want to ask.
Some websites allow a user to copy and paste some widget for use with their own site. For example, getsatisfaction. Yes, those feedback icons that I hope most of you see in various places.
If you have a look at twitterfeed, on the left there will be a feedback icon, once clicked on a nice modal window comes up. the modal windows content is in an iframe to an external source.
I really like this, but my question is:
I could do the same by using some jQuery library for the modal window and then linking the modal content to a site on my page, but how do I stop this from becoming obtrusive to a sites other javascript files?
For example, let's say i'm using my js code and the relevant jquery code, and i've minified it into one file. The user adds my widget to their site. If they're using jQuery, how do I make sure my code isn't going to interfere with theirs?
Would the best way be to use a modal window library which is not very popular?
Thanks very much. Hope that makes sense!
EDIT: I could write my own modal window functionality code, but i'd much rather use a library which already does it.
You can dynamically load jQuery only if it is needed.
First check for the existance of the jQuery object. If not add the script tag.
There are some challenges to this, as there is no onload event when adding a script tag to a page, that works consistently accross browsers, so you will have to poll to see if it fully loaded, and only then run your code.
There is an article on how to do this:
http://www.squidoo.com/load-jQuery-dynamically
You may still have an issue if the user has a differnt version of the jquery library though, although you can probably get around this with some additional checks.
jQuery UI has very nice dialog components that should fit your purpose. Inside them you can instantiate an iframe. see:
http://elijahmanor.com/demos/jqueryuidialogiframe/index.html
If I understand all this correctly, the iframe content is a separate page, so there is no case where your javascript code in that page would interfere with the javascript of the calling page, but maybe I haven't understood that part correctly?
EDIT:
I think I understand what you meant, in that you want to package up the code that you will write that opens the modal window with the iframe. SO you want to make sure that this code does not interfere with existing jQuery code that the user is using.
I think this is a good use case for a jQuery plugin. This way the user of the page can use your function like any jQuery function, so less likelyhood of collisions