Jump to content
Sign in to follow this  
RaviJ

Selenium with AutoIt

Recommended Posts

Hi,

I am calling following autoIt script with selenium

#include <file.au3>

AutoItSetOption("WinTitleMatchMode","2")

_Log("----new session----")
if $CmdLine[0] < 2 then
    ; Arguments are not enough
    msgbox(0,"Error","Supply all the Arguments, Browser name and path to upload")
    _Log("Arguments are wrong")
    Exit
EndIf

;Actiate firefox/IE browser
If (StringCompare($CmdLine[1],"firefox",0) = 0) Then
    $title = WinGetTitle("Mozilla Firefox") ; retrives whole window title
    _Log("FireFox selected")
ElseIf (StringCompare($CmdLine[1],"ie",0) = 0) Then
    $title = WinGetTitle("Windows Internet Explorer")
    _Log("IE selected")
Else
    Exit
EndIf

$hResult = WinActivate($title);
If($hResult == 0) Then
    _Log("Unable to find "&$title)
Else
    _Log($title&" activated")
EndIf

Sleep(2000)

;Handling of Request Authentication pop up if visible
if WinWait("Request Authentication","",20) Then
    $hResult = WinActivate("Request Authentication");
    If($hResult == 0) Then
        _Log("Unable to find Request Authentication")
    Else
        _Log("Request Authentication activated")
    EndIf
    sleep(1000)
    Send("{ENTER}")
EndIf

;mouse click for enable open dialog box
Sleep(20000)
MouseClick("left", 370, 494, 2)

;open dialog
WinWait("Open")
$title = WinGetTitle("Open") ; retrives whole window title
WinActivate($title)
WinWaitActive($title)
Sleep(1000)
$fullpath = $CmdLine[2]
Send($fullpath)
Sleep(1000)
Send("{ENTER}")

;used for logging
Func _Log($sLogMsg)
    _FileWriteLog(@ScriptDir & "\AutoItLog.log",$sLogMsg)
EndFunc

In java code as :

dialog =  new String[]{ "MultiFileUpload1.exe","firefox","E:\\Shared" };
Runtime.getRuntime().exec(dialog);
Thread.sleep(50000); // Need other solution  (1)

Everything is fine except (1). I need to provide sleep for 50 sec. because i am not able to identify when autoIt script finish using java So i have added fix maximum number of seconds when my script will finish.

If anyone known other solution for getting how to know that script is executing or not finish.

Thanks,

Ravi

Edited by RaviJ

Share this post


Link to post
Share on other sites

Thread.sleep(50000); // Need other solution (1)

I have got another workaround for it.

The another solution is :

int count = 0;
while (isProcessRunning("MultiFileUpload.exe") && count <= 50) {
    Thread.sleep(1000); // like WinWaitActive
    count++;
}

public static boolean isProcessRunning(String processName) {
        try {
            String line;
            Process p = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq " + processName + "\"");
            BufferedReader input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = input.readLine()) != null) {
                if (line.contains(processName)) {                    
                    input.close();
                    return true;
                }
            }
            input.close(); // the process was not found
        } catch (Exception err) {
            err.printStackTrace();
        }
        return false;
    }

Copy from the following post :

#837631

Thanks,

Ravi

Share this post


Link to post
Share on other sites

I have got another workaround for it.

The another solution is :

int count = 0;
while (isProcessRunning("MultiFileUpload.exe") && count <= 50) {
    Thread.sleep(1000); // like WinWaitActive
    count++;
}

public static boolean isProcessRunning(String processName) {
        try {
            String line;
            Process p = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq " + processName + "\"");
            BufferedReader input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = input.readLine()) != null) {
                if (line.contains(processName)) {                    
                    input.close();
                    return true;
                }
            }
            input.close(); // the process was not found
        } catch (Exception err) {
            err.printStackTrace();
        }
        return false;
    }

Copy from the following post :

#837631

Thanks,

Ravi

 

Hi Ravi,

Is it possible to pass the parameter from selenium to autoit script??

If yes please reply.

Thanks.

Share this post


Link to post
Share on other sites

I would also like to know the same thing , can we pass some value from selenium to Autoit and vice versa.

Edited by ankit14

Share this post


Link to post
Share on other sites

Did you search the forum? I got 88 hits when looking for "selenium".

BTW: Don't post the same question on multiple threads. Start a new thread - you will get much more replies.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites
if WinWait("Request Authentication","",20) Then
    $hResult = WinActivate("Request Authentication");
    If($hResult == 0) Then
        _Log("Unable to find Request Authentication")

how we will return this log value in our selenium script for validation purpose

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...