English 中文(简体)
How can I use Autoit to close all javascript alerts and confirmations that may appear?
原标题:

I am testing in selenium and I have a bunch of stuff that happens on page load. I found out about autoit, and I was thinking that it could handle all javascript dialog issues. I was searching around the web for some autoit script that could handle this...

Other options would be helpful as well!

I don t necessarily need all the code, but some point in the right direction would be helpful.

最佳回答

Alright so this solution works for me... I was able to close 2 windows here. Also I will be able to handle popups based on their name which is cool. It always runs in the background after I have lauched the script. When I want it to end I simply close autoit from task manager or from the task bar area on the right.

While True
If WinWait( Name of your Popup ,   , 1) == 1 Then
    ;Wait for page to load if found
    Sleep(10000)
    ;Close Page
    Send( !{F4} ) 
    Sleep(5000)
    ;Confirm Dialog
    Send( {ENTER} ) 
    Sleep(1000)
    ;Close Lanucher Page
    Send( !{F4} ) 
    Sleep(5000)
    ;Confirm Dialog
    Send( {ENTER} ) 
EndIf
;Let another thread have a turn
sleep(3)
WEnd

Also this is possible from directly within python, details: http://www.parrisstudios.com/?p=308, but you still need autoit3.

问题回答

If you are having issues with alert boxes you might want to disable them programmatically or create a separate mode in your code that would turn them off based on a condition (i.e. debug mode).

Macro recording programs don t work as well as you might think. Typically macro-recording programs record locations of mouse clicks and timing of key presses. The better macro-recording programs use (typically image processing) and (rarely) computer vision techniques. The solutions that use these techniques are typically VERY EXPENSIVE. (5k-10k per seat) [I can t remember one of the names of the better versions Might be QuickTest, but it was made by a company that was bought out by HP]

I was trying to interact with a webpage with autoit and the stupid javascript alerts kept breaking everything and I finally figured out how to disable them so I thought I would post it here:

#include <ie.au3>

$oIE = _IEAttach( https://www.site.com , URL )

$EventObject=ObjEvent($oIE.document,"IEEvent_")
Func IEEvent_onreadystatechange()
    $readystate=$oIE.document.readystate
    ConsoleWrite ($readystate & @CRLF )
    if $readystate= interactive  then killalert()
EndFunc

while 1
    sleep(100)
WEnd

func killalert()
Local $o_head = $oIE.document.all.tags("HEAD").Item(0)
Local $o_script = $oIE.document.createElement("script")
With $o_script
    .language = "jscript"
    .type = "text/javascript"
    .text =  function alert(message) {}; 
EndWith
$o_head.appendChild($o_script)
EndFunc

Basically what this does is have a function get called in autoit when the page ready status= interactive (apparently this is after most of the page has loaded but before it "runs" anything i think) that inserts some javascript into the page to redefine the alert() function so that it does nothing (no alert dialog to worry about having to click ok on). I have tested this and it works.

If you have the alert() function being called from a frame inside the page then you will have to use the onreadystatechange event and the readystate property of the frame instead of the main document.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签