Writing A Program that clicks a Chrome alert box - javascript

I have an alert that comes up in chrome, it slides into the browser on the top right hand side of the window. Every time this specific alert comes up I have to move my mouse over and click the alert box which will then open up a link in a new window. I have to do this multiple times a day. I'd be great if I could write a Javascript or Python program that will automatically "click" the box every time it comes up in the browser. Is there a way to do this? I have a little over a year of programming experience but I don't expect a step by step answer, just set me off in the right direction. I've looked up browser events hoping I could just write an event listener function but I couldn't find one specifically for browser alerts.

If it is the native modal of the browser, then the short answer is no.
You can't do it with javascript as the confirm (alert) pop up is a blocking modal.
No javascript code can run while the confirm modal is open.
If this is a custom modal that built and controlled by javascript then there is a good chance of doing just about anything you want with it.

Related

Popup window unrecognized by Selenium

Using Java, selenium and xpaths. I am verifying a Citrix project. Really all I have to do is login, show the favorites and apps buttons and that they are there. I get this window, which blocks everything:
And I can't do Selenium clicks until it is closed. Problem is, inspect does not show it, there is not a new windowhandle to locate it, and trying to find any xpaths does not work.
I can continue by using javascript clicks to click items blocked by this view, but it gets annoying and they may not accept it.
Before you suggest it, we are not allowed to use Robot. I looked for a Javascriptexecutor to just hit "ENTER" (since manually you can hit ENTER to download it) but couldn't find one. Uasing Actions(driver) does not work either because I think the window is not recognized.
There is a link "already installed" which I can click (with javascriptexecutor) and continue, but the popup window stays visible. Perhaps use Javascriptexecutor to open a link in a new window? But I tried some things which didn't work, although perhaps I did not have the right idea.
Any suggestions? BTW another solution that won't work is to do it manually the first time, because no matter how many times it runs and how many times the download button was clicked manually, the next time it comes up I get the window again.
Any ideas? (I scribbled out personal company info). Oh, and it is not an Alert. At least none recognized.

Javascript alert loop

I am very rookie when it comes to javascript, and I unwittingly created a alert which loops endlessly and means I cannot save the document and close the program.
Is there a way in surpassing the Javascript alert UI from the operating systems perspective, so I can still control the program.
I am running OSX 10.11.6 using Coda 2.
I cannot edit the code because the Javascript alert changes the focus to it then it appears, so then I close it another window appears.
I fixed the problem by hiding the program, then opening another document then going back to the document with the error I could save it. Then when I restarted I opened the program was able edit the code before It executed the code.

Simulating pop ups in windows javascript app

I'm porting my webpage chat to windows 8 javascript app. I need to simulate pop-ups like alert, prompt, confirm,... Creating the box isn't problem, but the main part is that I need to pause script execution somehow until user clicks the button.
Is there any way to do it (I know that in pure javascript, it is hard, but I think that there may be some kind of windows native function to pause execution (or there may be some way to implement alert,... directly))?
epascarello-- why do you say that its not makeable, if you dont know it.
use Method showModalDialog , search for it,

How to avoid the checkbox 'Stop execute scripts on this page' in the Javascript message box?

How can I avoid the checkbox 'Stop execute scripts on this page' in the Javasript message box?
Regards,
David
Quite simply, you can't. It's placed there for a reason - to stop sites that try to prevent you from leaving by popping up a new dialog box everytime you try to exit. In most browsers, like #Bazzz said, they don't show this until the second or third alert in a row.
You can't do that. It's a built-in feature in some browsers to prevent alert/confirm dialogs loop which can block whole browser. I can't image situation when many dialog downloads can be a good user experience.
Anyway, you don't have to rely on browser - just use custom dialogs in HTML/CSS which you can control as you wish.

Javascript close alert box

I want to be able to close an alert box automatically using Javascript after a certain amount of time or on a specific event (i.e. onkeypress). From my research, it doesn't look like that's possible with the built-in alert() function. Is there a way to override it and have control over the dialog box that it opens?
Also, I don't want an override that shows a hidden div as the alert. I need an actual dialog box.
As mentioned previously you really can't do this. You can do a modal dialog inside the window using a UI framework, or you can have a popup window, with a script that auto-closes after a timeout... each has a negative aspect. The modal window inside the browser won't create any notification if the window is minimized, and a programmatic (timer based) popup is likely to be blocked by modern browsers, and popup blockers.
Appears you can somewhat accomplish something similar with the Notification API. You can't control how long it stays visible (probably an OS preference of some kind--unless you specify requireInteraction true, then it stays up forever or until dismissed or until you close it), and it requires the user to click "allow notifications" (unfortunately) first, but here it is:
If you want it to close after 1s (all OS's leave it open 1s at least):
var notification = new Notification("Hi there!", {body: "some text"});
setTimeout(function() {notification.close()}, 1000);
If you wanted to show it longer than the "default" you could bind to the onclose callback and show another repeat notification I suppose, to replace it.
Ref: inspired by this answer, though that answer doesn't work in modern Chrome anymore, but the Notification API does.
no control over the dialog box, if you had control over the dialog box you could write obtrusive javascript code. (Its is not a good idea to use alert for anything except debugging)
I want to be able to close an alert
box automatically using javascript
after a certain amount of time or on a
specific event (i.e. onkeypress)
A sidenote: if you have an Alert("data"), you won't be able to keep code running in background (AFAIK)... . the dialog box is a modal window, so you can't lose focus too. So you won't have any keypress or timer running...
Try boot box plugin.
var alert = bootbox.alert('Massage')
alert.show();
setTimeout(function(){alert.modal('hide'); }, 4000);
I guess you could open a popup window and call that a dialog box. I'm unsure of the details, but I'm pretty sure you can close a window programmatically that you opened from javascript. Would this suffice?
The only real alternative here is to use some sort of custom widget with a modal option. Have a look at jQuery UI for an example of a dialog with these features. Similar things exist in just about every JS framework you can mention.
If you do it programmatically in JS it will be like reinventing the wheel. I recommend using a jQuery plugin called jGrowl
You actually can do this you can basically listen for this pop up to happen and then confirm true before it ever "pops up",
if(window.alert){
return true
}
You can use label and set its fade in and out time for e.g
Hide it initially and show on click.
$('#div_Message').fadeIn(500).delay(1000).fadeOut(1500);
window.setTimeout('alert("Message goes here");window.close();', 5000);

Categories

Resources