Trouble with greasemonkey script to refresh page - ajax

I'm downloading data from an online database using the imacros plugin for firefox. It works perfectly, except when the page times out. I've moved to downloading very small chunks of data since then the website times out much less frequently, but it still times out occasionally.
The problem is there's no way to code if statements directly into the imacros macro, so I wanted to have a greasemonkey script running along side it that will refresh the page if it timesout. The website only times out in one place for me, and when it does it shows the following:
can't open file
I never learned Java or Javascript and all of my programming experience deals with numerical methods, but I've been been piecing together code and adapting it to try and solve my problem.
The following is my base code:
var RefreshTime = '20';
var str1 = document.body.innerHTML
var str2 = "can't open file"
if (str1.search(str2) > 0) {
if (StRefTime > 0) setTimeout("location.reload(true);",RefreshTime*1000);
}
Since the browser I'm running this in is currently being used exclusively for this script I just have #include *
Basically what this is meant to do is refresh the page every 20 seconds as long "can't open file" is found the webpage. This works perfectly on other websites when I test it, but doesn't work at all on the website I need it to. It might be worth noting that when I refresh, firefox asks me to confirm resending post data - but imacros does have a function that I tested and works on this site to automatically confirm whenever the dialog is displayed.
After doing some reading I found that other people had similar problems, and I think the root of the cause is that if the page is arrived at through AJAX then greasemonkey misses it.
To address this I tried to implement the suggested solutions to those people, but I've been unsuccessful. For example I've tried putting the code I listed above into the solution given here: Run Greasemonkey script on the same page, multiple times? , for example
var RefreshTime = '20';
var str1 = document.body.innerHTML
var str2 = "can't open file"
function highlightGoodComments (jNode) {
//***** YOUR CODE HERE *****
if (/str2/i.test (jNode.text () ) ) {
if (str1.search(str2) > 0) {
if (RefreshTime > 0) setTimeout("location.reload(true);",RefreshTime*1000);
}
}
But this doesn't work either, and I've tried a couple variations of it (for example getting rid of str2 and just putting "open file" and things like that) and I've also tried and failed to make the following work https://gist.github.com/BrockA/2625891. I also tried wrapping all of my initial code in a setInterval loop with the hope that it would just check constantly for "can't open file" even without any page loading, but that didn't work either.
Unfortunately the website I'm running my script on is hidden behind a paywall, and it's hard to test my code since it times out somewhat randomly so there's no way to check if my code works outside of just waiting a long time and seeing if it failed. I know nothing about AJAX, so I'm not sure how to confirm that that is what's happening, but I still believe it to be so since my problem seemed similar to other people's - and when I enable this macro it does seem to interfere with other parts of the website but not the parts that my script works on.
I was hoping somebody could help me out, since I'm pretty stuck here and already in over my head. Even if you can't help, having some sort of AJAX website where I could test code without waiting several hours would be helpful to me trying to figure this out myself, if anybody knows of one. Thank you for reading through this, I really do appreciate any help anybody can offer.

The question is very long so I didn't bother to really read it. Since I don't use GreasMonkey I can tell you the iMacros solution.
Check if html element exists with iMacros and javascript
Here is a model how to built JS iMacros script and include if clause. You can make a testing macro that tests is t here "can't open" web page.
Also you can try to use
SET !TIMEOUT_PAGE 120
command to increase the time of page loading to 120 seconds. Try some of these if it can help.

Related

Select() method and option() method works differently

Today I have seen a question in selenium C# section where this question was posted, I try to solve that problem through WATIR coding, I have written the below code and WATIR identifies this select list as invisible.
b.goto 'http://automationpractice.com/index.php'
b.img(title: 'Faded Short Sleeve T-shirts').click
b.iframe(xpath: "//*[starts-with(#id,'fancybox-frame')]").select_list.select("L")
But If I select that same select_list through below metioned code, it works fine.
b.iframe(xpath: "//*[starts-with(#id,'fancybox-frame')]").select_list.option(text: "L").click
I don't understand what is the difference here, when I put a debug pointer, both are making a selenium call to find_element(tag_name: "select"), first one fails due to element invisible but second one passes
#Titus, #JustinKo Can you please explain me what's happening here? what's the difference?
Note: Please run it in Chrome.
Moving from a comment to an answer:
The issue is that we refactored the normal (non-select-list) way of doing it to not check for whether an element is displayed ahead of time, and put the waiting logic in the rescue block if Selenium complained. The select-list code is still checking the visibility ahead of time, and this particular select-list element is not displayed according to Selenium. Since it appears that Selenium can select options without select list showing as displayed, Watir should not be waiting for this.
I've fixed it here, and it will be working in Watir 6.13 (should be released "soon")
https://github.com/watir/watir/commit/77af164fcdecb71d8d2240110d3fb4b1dabeee4b

free-jQgrid "loading" message still remains

Since my app is online for to be tested by customer, I often meet this problem and I have to click several times on "Tiers" menu to hope it will disappear and give hand.
Here is a snapshot of the trouble :
WHen I use my app on local server (wampserver) I never meet this trouble.
I have several grids in my app and none displays this message online.
Firebug says "jquery.jqgrid.min.js" has error in line 344 (?). Used version is 4.13.5-pre dated 2016-08-27 and hosted server runs with php 5.6.8
Does somebody already met this type of trouble ?
If somebody can take some time to help me, I can give by email login and pass to test app online.
Many thanks for your kind help.
Cheers
JiheL
Thank you for reporting the issue. It would be helpful if you report the error using jquery.jqgrid.src.js instead of jquery.jqgrid.min.js, but I suppose that the only place in the code, which could produce the error is the piece of code with if ($input[0].tagName.toUpperCase() === "SELECT" && $input[0].multiple) {... (see here).
I posted the fix just now, which should eliminate the error. It includes the additional test if ($input.length > 0) {...} (see the line). I would still recommend you to examine the name and index values in colModel of your grids. It seems that your current code uses the filter with names or index, which is not from colModel or which uses some special characters. It's the only reason of the error, which one can see in console of your picture.

slow typing due to Sys.Desktop.KeyDown and Sys.Desktop.KeyUp methods

We are using Sys.Desktop.KeyDown and Sys.Desktop.KeyUp VB methods of TestComplete to type into Notepad.
For this we are using a for loop containing KeyDown and KeyUp, however for some reason, even after the for loop ends, the typing is still not complete, its typing slowly, not sure why.
I checked by removing anti-virus software, but still seeing the issue. I have also tried to use the Win32API.GetKeyState(Asc("A")) however sometimes we get 1 and sometimes 0, so really need to debug this issue out. Could anybody suggest a way to debug this issue?
Are you able to use .Keys() on the main text area object?
Something like:
Set textObject = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1)
Call textObject.Keys("Hello")
This is my preferred way of sending text when it is directed toward a particular object. Please refer to this link for more information on the Keys method.

Google spreadsheet ImportXML Error:"the XPath query did not return any data"

I continue to get this error when I try to run this XPath query
//div[#iti='0']
on this link (flight search from google)
https://www.google.com/flights/#search;f=LGW;t=JFK;d=2014-05-22;r=2014-05-26
I get something like this:
=ImportXML("https://www.google.fr/flights/#search;f=jfk;t=lgw;d=2014-02-22;r=2014-02-26";"//div[#iti='0']")
I verified and the XPath is correct (I get the answer wanted using XPath helper, the answer wanted are the data relative to the first flight selected).
I guess that it is a problem of syntax, but I tried more or less all the combinations of lower/uppercase, punctuation (replacing ; , ' ") and I tried to link the URI and the XPath query stored in cells, but nothing works.
Any help will be appreciated.
As a matter of fact, maybe it is a bug on the new google sheets or they have changed how the function works. I've activated mine and when I try to use the ImportXML it simply wont work. Since I have some old sheets here (on the old mechanism) they still work normally. If I copy and paste the script from the old to the new one it simply doesn't get any data.
Here a example:
=ImportXML("http://www.nytimes.com/pages/todayspaper/index.html";"//div[#class='columnGroup first']//h3")
If I run this on the old mechanism it works fine, but if I run the same on the new mechanism, first it will exchange my ";" for a "," and then it will bring a "#N/A" with a warning of "Error: Imported XML content cannot be parsed".
Edit (05/05/2015):
I am happy to say that I tested this function again today on the new spreadsheets and they've fixed it. I was checking that every two months and now finally they have solved this issue. The example I've added above is now returning information.
I'm sorry, but you won't be able to easily parse Google result pages. The reason your function throws an error is because the content of the page you see in your browser is generated by javascript, and Google spreadsheet doesn't execute js.
Your ImportXML has the right syntax, it doesn't return anything because the node you're looking for isn't there (importXML Parse Error).
You will have to find another source if you want these result in your spreadsheet. For info some libraries already parse the usual result page (http://www.seerinteractive.com/blog/google-scraper-in-google-docs-update for example, if it still works), but I doubt finding one for your special case will be easy.
This gives the answer (importXML Parse Error), but it's not entirely obvious.
ImportXML doesn't load Javascript. When you're building ImportXML queries on Google results, make sure you're testing against a version of the page that has Javascript turned off. You can do this using the Chrome DevTools.
(But I agree that ImportXML is fickle, idiosyncratic, and generally rage-inducing).

Ruby/Watir getting stuck after using "goto"

I'm using a simple browser.goto(url) call to our Microsoft SQL Reporting pages. It does a "goto" on the first url but then just sits there. I'm currently running it via command line.
If I Ctrl+C to cancel it, the output says:
C:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/ie-class.rb:506:in `wait': Interrupt
from C:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/ie-class.rb:355:in `goto'
from screen.rb:37:in `SqlReports'
from screen.rb:35:in `each'
from screen.rb:35:in `SqlReports'
from screen.rb:45
So, I'm guessing something on the page is causing Waitr problems. I've googled the about snippets, but not come back with anything. All I want it to do is load the page, sit there for a specified time, then move to the next url (it's for a tv screen), nothing complex.
So I've tried placing a "begin/rescue" ie:
begin
$browser.goto(url)
rescue
end
No luck, it just sits on the first url. And I've tried wrapping that using the Timeout class, ie:
begin
Timeout::timeout(30) do
$browser.goto(url)
end
rescue
end
Still no luck, it crashes out. Does anyone know a fix, or how to override the implicit "wait" that Watir does when doing a goto?
My guess would be that there is something on that page that keeps IE from saying "I'm done loading everything here".
There is a $browser.click_no_wait command and a $browser.click! command, so if you had a static page that had a link to your url, you could $browser.goto that page and clcik_no_wait the link.
an excellent solution using timeouts at http://watirboy.blogspot.com/2010/07/watir-timeout-handle-browser-hangstuck.html

Resources