Dismissing a print dialog in Nightwatch? - javascript

I'm using Chrome as a browser and can't quite figure out how to dismiss a print dialog that appears on click of a particular button.
I have tried using browser.dismissAlert(); and browser.keys([browser.Keys.ESCAPE]); to hit the escape button, and neither works. I'm not sure that Nightwatch is aware that there is a dialog at all.
I've been searching online and can't seem to find a solution... anyone got any ideas please?

So, as it turns out, Selenium cannot handle Chrome dialogs. I did however find a solution by reading this page and adding --disable-print-preview to the chromeOptions in the nightwatch.json file in my project.
This dismissed the Chrome print dialog, but still brings up the Mac system dialog, and I don't think Selenium capabilities extends to system dialogs, so for the purpose of testing, I've just disabled the print functionality.
Shame I didn't find a better solution, but just wanted to update for those of you upvoting

Related

Moodle action menu and edit popup don't show with activity plugin

I created a moodle action plugin to embed videos and everything works fine. Expect the Action menu and other popups.
So normally it should be shown like this
But when I enabled my plugin on the click nothing happens.
And it is not working until I uninstall the plugin completly. Uninstalling is not enough I also have to remove it from the file system.
I don't have any clue whats the problem because my plugin have nothing to do with this action menu or edit popup in a course. It's just adding an activity and show a video.
Any idea why this problem occurs in moodle and what is maybe wrong with my plugin?
It sounds like a javascript error, which is stopping all the rest of the javascript on the page from running.
I suggest you open up your browser's debugging tools and look to see if there are any errors appearing - then investigate to see what needs doing to fix them.

How do I run a custom script when I view a website?

For example, I want to copy text from this website: http://cafe.naver.com/4korean
But they have disabled right click menu as well as any kind of text selection on the website
After a little searching in Google I found this script: http://userscripts.org/scripts/review/61326
which is supposed to disable the protection on their website
However, I am not able to figure out how to run this code
I pressed F12 and went to the Chrome console, but when paste and run the code, I just get the message undefined (which I am sure was some other red coloured error message when I had tried the same thing just this morning)
I am not sure if there is any problem with the script, or with the way I am running it.
Please help.
Thank you.
PS: I am not sure how to tag this question. I think the script is javascript but I am not sure. Please provide some suggestions on this as well. Thanks.
Hers is the Link which will let you study how to re-enable right click on website, try it for once.
Hers is the anothere one Link2
Besides, that there come a plugin for Mozilla Mozilla Right to click and chrome Chrome Allow Right Click, you can have it whatever you wants.

preventing a browser from losing focus on external app call

I'm building a quick VOIP demo using Skype and when I press a call button, the Skype application takes the focus away from the browser. You can try here http://developer.skype.com/skype-uris/skype-uri-tutorial-webpages where you'll find several "Try it here" links. When I click those links, I would like the browser to maintain focus. Is there a way to do this?
Thanks.
What you would need to do is apparently called "focus stealing" from my web searches.
At least as far as Windows is concerned, there does not seem to be a reliable way to do this from the browser alone.
I just googled "focus stealing" (which is what the JavaScript only solution would need to do to get this done) and found many answers showing that, though theoretically possible, depending on the configuration of Windows stealing the focus away from Skype by the browser would probably not work in the majority of cases.
The complaints in the Google links are numerous and some answers conflict, but it looks like reliably "stealing the focus" back to the browser is not going to be supported.
This is a good thing though, if you think about it - I do not personally want just any old JavaScript program running in my browser to change my focus from what I am working on back to the browser willy nilly - this would be a very annoying behavior for a web page to be able to do at best, making my system useless at worst.
If you could do it in this case using some methodology allowed in a browser, so could anyone else - even malevolent websites.
The best answer is to never let the focus leave the browser, but I have no idea how to do that in your specific case. Perhaps whatever means you are using to launch Skype may have an option or something to launch it in the background or whatever, never changing the focus.
I did not hit on specific links pertaining to Apple OSes, Linux or mobile OSes, but I have a feeling the same concerns and limitations apply for those as well.
Here are some of the links on the Google search (and sorry about the bad news for your needs):
Microsoft Answers Forum Post
Focus stealing is evil
http://pcsupport.about.com/od/windowsxp/ht/stealingfocus02.htm
you can open it on new window, then close the new window and refocus on yours
somthing like:
a=window.open('skype:ohadcn?chat',10,10);
//i couldn't find a relevant event, onload() do not work for me here
//so i used setTimeOut, hoping that two seconds is enough to open skype but not enough to loose the user
setTimeout(function(){ a.close();window.focus();},2000)
I went to the skype tutorial page in Chrome, brought up the console and tried Ohad's answer, but it would not return the focus to the tutorial web page.
I even tried a script to perpetually put the focus in the Search textbox:
function ASDF() {
document.getElementsByName("q")[0].focus();
setTimeout(ASDF, 1000);
}
setTimeout(ASDF, 1000);
Still no luck.
I tried changing Ohad's script so that it would reopen the tutorial page in a new window after the skype app opened. It would work if the tutoral/console page was the only tab in the window:
a=window.open('skype:ohadcn?chat',10,10);
setTimeout(function(){
a.close();
a=window.open('http://developer.skype.com/skype-uris/skype-uri-tutorial-webpages', 10, 10);
window.close();},2000);
However, if the tutorial page/console script was in window with other tabs, it did not return focus to the reopened page. Not to mention, IE might warn the user that the original page is trying to close.
I do not think there is a way to consistently achieve your goal, but I reserve the right to be wrong.

Chrome issue when using jquery

Am using the confirm message when delete the record from the table.When I click and delete the records got "prevent this page from creating additional dialogs chrome".How to disable the prevent this page from creating additional dialogs in Chrome alert?
What are the chrome settings changes are required to disable the messages?I googled lot but no luck.
Thanks in Advance..
As others have said, this is a built-in safety net on Chrome (and other browsers, Firefox for example) that you can't work around (nor should you try). Its purpose is to prevent websites "locking" the page by repeatedly throwing alerts; for every alert you dismiss, a new one surfaces. It used to be the case that the whole browsers was "locked" until the alert was dismissed (try it in IE6).
At the risk of going Off Topic, I would be inclined to re-consider your approach: instead of asking the user to confirm an action, give them a means to undo it instead. More often than not, the "delete" action was intentional, so adding the extra interaction is likely to be a PITA for power users. Similarly, it's entirely likely people will become blind to the alerts and dismiss them without even reading them, such that they serve no purpose at all.
See: http://patternry.com/p=undo/ and Never use a warning when mean Undo
You can't. It's a behavior of the browser. It doesn't depend on JavaScript.
Its the default behaviour of Chrome. If you are showing frequent alert/confirm then it will show this, and the worst thing is if the user check h check box, no alert and confirm will be shown afterwards.
You can use Jquery Poup to show any message or get any data from users

disable onclick ads with a content-script in Google Chrome

There are some video streaming sites that pop up an ad anytime you click anywhere on the page. The problem is, you have to click on the page to press play! So I was thinking of making a UserScript that disables the script that does this. The only problem is, I already disable all the scripts on the site and when I do it still pops up. Is there a way that I can disable them ? I'm also using jQuery, so if I can do it through their interface, that would be great.
edit: Two perfect examples of such sites are daclips.in and gorrilavid.in
I have Adblocker Plus, and it seems like it is not recognizing "on Click" events as pop-ups, rather normal clicked links. And the logic is simple, no Adblocker will block you from clicking something intentionally and it (the link) opening in another window/tab.
The problem is the new window contains your clicked Url, while the original window/tab "Refreshes" (i.e. redirects) to another url.
Advertising companies seem to use this trick to bypass adblocking software.
Just ditch Chrome and use Firefox. Firefox already have built-in mouse-click popups. I think all addons like Adguard or Adblock can not disable mouse-click popups. If you use Firefox, these are the steps:
Type about:config in the browser's address bar and hit the enter key.
First time users need to confirm that they be careful on the next page.
Type or paste dom.popup_allowed_events into the search field.
The value of the preference highlights all events that are allowed to spawn popups.
Edit the value to remove some or all of the items here.
Why not just use a browser extension such as AdBlock?
https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom?hl=en
My go-to is right click and open in new tab. onClick events only happen with a left click. It's cumbersome but it still ends up being less work than closing the pop-up and whatever annoying prompts it may have.
I do not there's a practical solution for this.
Moreover, I think some of the answers here are missing the specific case in OP, where clicking anywhere on the page will cause the pop up to happen, not just clicking on links. According to this, neither right-clicking then choosing "open", nor noticing and blocking the target URL will help. I do not know of an add blocker that helps here either, because it's not trivial to meaningfully filter a click event that is taking place on the whole page object.
Only the solution provided by #Monkey would work, at the drawback of possibly breaking other things.

Categories