In my django app I use Ghost.py to render a web page with some Javascript. The problem is that sometimes the JS takes a while to run and Ghost.py thinks that my JS script is not working well and raises the typical confirmation box asking me whether I want to terminate the script.
In my machine I see that the confirm box comes up and press the 'No' button when it asks me to terminate the script. But when it's running in an AWS EC2 instance, that confirm box causes a dead lock because it will keep waiting for someone to press the 'Yes' or 'No' button.
Is there a way to automatically press the 'No' button every time a confirm box shows up?
I tried using:
ghost = Ghost(wait_timeout=20)
ghost.confirm(False)
ghost.open(html_path)
ghost.capture_to(img_path)
as well as this:
ghost = Ghost(wait_timeout=20)
ghost.open(html_path, default_popup_response=False)
ghost.capture_to(img_path)
The documentation on the topic is scarce. Any help is appreciated.
Related
This may be basic, but it's something I'm not able to find the answer to.
I need to write an event listener, which listens for alerts / confirm boxes displayed on the page, and this is what they're expected to do
When there is an alert
Detect that there is an alert on the page.
Capture the alert message
Detect when the user is pressing the OK button (basically an event handler for the alert OK click)
When there is a confirm box
Detect that there's a confirm box
Capture the message
Detect what button the user is clicking. Is he/she accepting the alert, or is he/she dismissing the alert.
I need this for a side project I'm working on, which simply collects some stats from a specific web app and sends back some data for analytics. There are a lot of Confirm boxes on the page, and I would like to record the decisions taken by users.
This could be thought of as a browser extension for Firefox, Chrome and/or IE, which runs in the background and listens to user interactions and report them elsewhere.
I have gone through a post: Click Here, but it doesn't seem to answer my question.
Please help
Thanks,
Sriram
Using Python 3+ and Selenium > IE Driver.
I am running a python script to automate the setup of a user on system as there isn't any other way then using the webpage.
The problem that I am having is when I try to navigate away from a page if the user is a duplicate, I am getting a JS alert asking me if I am sure I want to leave the page because of unsaved data.
I have tried the below code.
alert = browser.switch_to.alert
alert.accept()
Python seems to stop and doesn't continue to interact with the browser till the JS alert has been cleared. For example the Python window will display the flashing busy indicator like its doing something in till I select "OK" on the alert. Once this has been done the code will continue to run and return a Alert exception because the alert is no longer there proving that the script is waiting for the alert to be handled before continuing.
If anyone could add to this or point me in the right direction I would be greatly appreciated.
Alert Image
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.
I am trying to automatestrong text a certain task and the procedure of it is as follows:
Open web browser (Google Chrome)
Go to a certain site
Put in username then jump to another field (like pressing the Tab
button.. it automatically log ins since I am connected to the
office network)
Type again on a certain field
Click search button etc etc
Is it better to code a windows service? Are there any other ways to do the above task? I wanted to automate it because the job is just more about Click, Type, Click, and Wait. The values are also somehow fixed so it could really be automated.
I am currently modernising some plugin modules from version 2.x to the OSGi-based 4.x. This project uses the Eclipse application and takes advantage of its view & perspective architecture to serve as a tabbed browser.
Studying the old code and running the Eclipse application, this is what I understand to be the expected behaviour of one particular functionality:
Clicking a link opens a panel in a new tab, which displays a HTML file containing Javascript in it.
The HTML page contains a form culminating in a Submit & Cancel button.
Clicking either button should close the tab. The submit button will, of course, first submit the form data.
Most of the above works as intended, however instead of closing just that one tab, clicking either button causes the entire Eclipse application to attempt to terminate (I received a confirmation prompt asking if I want to exit Eclipse). The submit button did successfully update submitted info into the database before attempting to terminate the Eclipse application.
This is what the offending part of the code looks like:
function onSubmit() {
//processForm();
if (opener) {
opener.newAddressValue(newToAddress);
window.close();
} else if (parent.parent) {
parent.parent.newAddressValue(newToAddress);
parent.parent.closeUsrFrame();
} else {
parent.newAddressValue(newToAddress);
parent.closeUsrFrame();
}
}
function onCancel() {
if (opener) {
window.close();
} else {
parent.closeUsrFrame();
}
}
I suspect the expected behaviour is for program flow to reach window.close() at which point the tab containing the opened panel should close, but instead it is causing the entire Eclipse application to terminate. What is the correct way to exit the current tab in Eclipse 4.x using JavaScript?
If the program display a HTML file using SWT Browser widget, you can use Browser.addCloseWindowListener(CloseWindowListener listener) to hook the event that triggered by javascript window.close.
If your program do prompt about exiting Eclipse, you shall search class that implement CloseWindowListener interface. Modify its behavior as you wished.