Identifying Tab / Window to click a button using JavaScript (AppleScript) - javascript

I am trying to get an Apple Script to click on an item within webpage.
I'm using the following script
tell application "Safari"
delay 5
do JavaScript "document.getElementById('Menu Principal').click();" in current tab of first window
end tell
However my output us "missing value". I think that the problem is that I'm not selecting the right tab or window to click at.
This is my first time using applescript and other examples and question in Stackoverflow are somewhat similar but I'm still missing something
I'm attaching the webpage source code.
Thanks!
http://s328.photobucket.com/user/sergioguerra1/media/ScreenShot2014-03-13at114430AM_zps6919a8ce.png.html

Related

How does an auto refresh page extension works and how to recreate one with code?

I'm looking for a way to recreate the functionality of a refreshing page extension on a browser (e.g. Auto refresh plus in Chrome) by using javascript. The problem is that I have no ideia how to achieve that.
I must find a way to refresh the page every second or so, click on a link that appears on the page from time to time, add a sound effect for when it appears and send an e-mail notification every time it appears.
I'm trying to use a simple javascript snippet to run in the console in order to refresh the page:
win1 = window.open("https://www.myUrl.com/");
timer1 = setInterval(function(){win1.location.href="https://www.myUrl.com/"}, 1500);
However, this implies running code from tab A on tab B which I found very challenging.
The code can't run on tab A alone because at the time it refreshes the page, it gets erased from the console.
I know it would have been so much easier to use an extension, but the platform I work for does not allowed any extensions.
I have basic HTML and javascript knowledge, but I find this would be a good project to learn more.
Also, if the solution involves other languages, I just need a direction to know where to look for and start this project.

Selenium IDE - timing of chooseOkOnNextConfirmation during page forward

I'm trying to book a table at a restaurant. After I click on the book button, the page forwards, checks back to confirm availability with the server (over the course of maybe 2 seconds) and then opens a JavaScript confirmation pop-up in the browser.
Will I be fine with chooseOkOnNextConfirmation before I press the button and thus before the page forwards or should I add another (or move) chooseOkOnNextConfirmation after the click during the availability check?
Would it hurt to have several chooseOkOnNextConfirmation commands in a row? Would they interfere with each other?
It is essential that I get the timing right. Too early and the command might be executed on the wrong page, too late and the JavaScript pop-up stops my script. Please note that I can not test the script nor can I look at the page's JavaScript properties as bookings are closed right now and will only be available later.
Alternatively, should I use clickAndWait instead of click (the URL doesn't change though and the command may cause errors)? Can I use assertConfirmationPresent to determine whether the page is fully loaded before assertConfirmation or will it be too late since the pop-up already stopped my script?
What I have for now looks as follows:
chooseOkOnNextConfirmation
click //*[#id="table_id"]/thead/tr/th[1]/input
assertConfirmation glob:Are you sure you want to submit your request
for the following unit: Location Description:*
Btw, turns out globbing doesn't work for the command assertConfirmation. I get the error Confirmation message doesn't match actual message in the log unless the text in target matches the text in the pop-up exactly. Any ideas how to work around or how to make glob:* work?

Browsing 1 link and out another tabs with different links

I want to write codes in my blogger to show when I browsing link likes www.12345.blogspot.com(example) ,after loading inside ,it will auto out anothor tabs in browser to run links which set by me.
So, example is i typing link of www.12345.blogspot.com and press enter to browse and will out another tabs likes www.youtube.com ,the focus point in webpage still in first (www.12345.blogspot.com).
Any codes could write about what I describe? Sorry for my bad english
If I understand you correctly, when loading a website, you want to open a second website in a separate tab while maintaining focus on the first tab. Here's how you'd do it:
var w=window.open("https://google.ie");
if(w)w.blur();
I would, however, advise very strongly against doing this.

waitForKeyElements(); - Stop a script firing on a popup in Chrome Extension?

This question is a follow-on to another question which needed asking and warranted a new post, so excuse me if I refer to things which may not be clear without reading the other question.
When using the utility waitForKeyElements() I'm facing an issue in which a div is included inside a small popup contained within the same URL. My extension is currently running on the Twitter site, and my intention is that a div contained on the profile pages (e.g. http://twitter.com/todayshow) gets moved above another div on the page. I'm doing this via waitForKeyElements() because of some loading issues which are resolved by using this utility.
However, on a profile page you can click a link to another users name which pops up a small window (inside the same window/tab, on the same URL) showing some info about them and a few previous tweets. The issue here is that the same div appears on this popup and is then moved to the main page behind the popup window, where it shouldn't be. On a profile page, this can be stopped by plugging in the false parameter to waitForKeyElements(), however on a non-profile page it is still possible to activate this popup which is then moving onto the main page, as the div I wish to move it above on a profile page still exists here, causing clear issues.
I'm wondering if there's a way around this, as bugs in Chrome have stopped me from excluding these pages. So far (just brainstorming) I'm thinking:
on a page where the div doesn't exist to begin with, create an empty one meaning false will handle the issue.
somehow stop the script from firing on a given URL, although due to the way Twitter works this would have to monitor OnClick() and the page URL (I think) which I'm unsure how to do.
stop running when the popup appears, but I have almost no idea where to start with that.
Any help is appreciated. Any necessary code related to this question can be found in the first two links, and the issue I'm facing can be seen by a quick visit to Twitter.
EDIT: When plugging in the false param it works when going directly to profiles via the URL bar, if you're on a profile and use a link to get to a profile, the script isn't inserted and my extension fails. So this would need resolving too, or an alternative method altogether.
I had a brainwave that I could use insertAfter() to insert the <div> I was originally moving in front of, after the <div> I was originally moving. This <div> is not present on the popup, which means that nothing is moved onto the back page when it shouldn't be.
In regards to the previous question, my code is now simply:
waitForKeyElements (
"jQuery selector for div(s) you want to move", // Opposite to what it was.
moveSelectDivs
);
function moveSelectDivs (jNode) {
jNode.insertAfter ("APPROPRIATE JQUERY SELECTOR"); // Again, the opposite.
}
This solves the issue I was having and my extension is now working just fine, however I will leave this question posted in case anybody comes back to it in future.

link running a javascript that open another page. how to make it do it in new tab if user uses middle click or right click menu

I have this link in my left navigation:
dashboard
That javascript opens a link based on the passed parameters.
All works fine, but I would like to be able to use the browser capabilities of opening the links in a tab (when user is using middle click or selects 'Open link in new tag' from right click menu). Though, this is not working for links handled with javascript code.
There are many reasons why this is not the default behaviour of the browser (e.g. javascript function might only do some validation and stay in the page ... browser can't know what the js might do or if a new window/dialog will result from that action so would make no sense to open new tag as a result of a middle click ...). But hopefully there is a workaround for the default behaviour.
Any idea how this could be done?
Cheers,
Stef.
Javascript links execute in context of the page where they are called. If you "open" the link in a new tab/window, the javascript code will be executed in the new window, i.e., empty, and will most probably fail.
A browser could try to add the feature you are asking for by cloning the page which contains the link, and executing the javascript code in the context of the cloned page. But this would most likely break some critical sites (imagine for example that your online banking site works with javascript, so when you open a link in a new tab/window, cloning the original window might lead to a duplicate transaction).

Categories

Resources