Jump to content

_FileDragDrop.au3 works for Notepad++ but not for Firefox


Recommended Posts

I have a simple code that takes file "C:\Temp\File1.txt" and pastes it in drop area of specific firefox location ( Note The drag drop works manually meaning firefox window supports drag and drop)  . The return value is true with no error indicating that operation successful.

The results are not getting updated in firefox window even after exe execution completion and sleep time 20secs.

Attached my code snippet and _FileDragDrop.au3 + text file it works 

#include "_FileDragDrop.au3"
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("MouseCoordMode", 0) ;1=absolute, 0=relative, 2=client

$File1 = "E:\AutoIt\DragDropFile\File1.txt"
$File2 = "E:\AutoIt\DragDropFile\File2.txt"
If ProcessExists("Firefox.exe") Then
    $hWnd = WinGetHandle("Mozilla Firefox") ; My FF tab title substring
    WinActivate($hWnd)
Else
    MsgBox(64,"Error","No Firefox window found",10)
EndIf


$hNPPlus=WinGetHandle("[CLASS:Notepad++]")
WinActivate($hNPPlus)
$iRet = _FileDragDrop($hNPPlus, $File1, 75, 274)
ConsoleWrite("Return: "&$iRet&" @error="&@error&", @extended="&@extended&@CRLF)
Sleep(20000)
;~ Above code to add in Notepad++ works fine

;~ Cordinate from drop file 1 - 75, 274
$iRet = _FileDragDrop($hWnd, $File1, 75, 274,'|',False)
ConsoleWrite("Return: "&$iRet&" @error="&@error&", @extended="&@extended&@CRLF)
Sleep(20000)
;~ Above code to add file in firefox with title Mozilla firefox DOES NOT work

Exit

1959592042_FFImage.jpg.df654d047fdc76e63d0f255fb8561f93.jpg

 

Repose from code -->

Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
Return: True @error=0, @extended=0

Return: True @error=0, @extended=0

 

_FileDragDrop.au3 File1.txt

Edited by MakzNovice
Typo in snippet

It doesn't get easier, you just get better...

Link to post
Share on other sites

Take a look for: 

_WD_SelectFiles()

in WebDriver UDF.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2022-03-07

Link to post
Share on other sites

@mLipok

I am trying the webdriver UDF as given in sample for firefox, I am stuck at very basic step though..

1. I have my firefox session page already launched, how can I gets associate it Session created by _WD_CreateSession?

_WD_Navigate - opens new page, if I pass second argument as URL, which requires login and everything else( not what I desire)

I tried $hWnd = WinGetHandle($sTitleString) and then _WD_Navigate($sSession,$hWnd) but it fails too.. 

_WD_Attach - looks for page by title created in session and fails

 

My aim is to read the page that I already have, but all the _WD_* operations seem to need session id created using _WD_CreateSession.

I want to know how can I read existing firefox webpage and be able to call methods like _WD_SelectFiles or _WD_FindElements

Any snippet would be of great help here

 

2. In _WD_SelectFiles($sSession, $sStrategy, $sSelector, $sFilename) , what types of drop are supported

As per documentation of method -   $sSelector - Value to find. Should point to element of type '< input type="file" >'

The information that I have about by drop location by developer tools is - <div id='divFiledrop' class='dropArea'....

does the class gets supported by this method ?

 

Any response will be highly appreciated

Edited by MakzNovice

It doesn't get easier, you just get better...

Link to post
Share on other sites
1 hour ago, MakzNovice said:

I have my firefox session page already launched, how can I gets associate it Session created by _WD_CreateSession?

_WD_CreateSession() create new session not the one you have already launched manually.

1 hour ago, MakzNovice said:

_WD_Navigate - opens new page _WD_Attach - looks for page by title created in session and fails

_WD_Attach() can attach only to sessions started with WebDriver not manually.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2022-03-07

Link to post
Share on other sites

Hi MakzNovice,

40 minutes ago, MakzNovice said:

So is there a way to get handle of existing page or no option to get it?

When you mean you would like to use your local and manually opened Firefox browser, then basically no, not as far as I understood it.

  • You start with a new WebDriver instance (other then your manually opened Firefox browser).
  • You do all the navigation and probably clicking steps to reach your target drop area like you described in the first post.
  • Then you are at the point to do your drag and drop actions by WebDriver functions.

Please correct me if I am wrong @mLipok or @Danp2, but stealing a browser session into the opened WebDriver session isn't possible, am I right?
At least not without specific security-attacks or something ... I don't know.

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART
Link to post
Share on other sites

Hi MakzNovice again,

2 hours ago, MakzNovice said:

2. In _WD_SelectFiles($sSession, $sStrategy, $sSelector, $sFilename) , what types of drop are supported

As per documentation of method -   $sSelector - Value to find. Should point to element of type '< input type="file" >'

The information that I have about by drop location by developer tools is - <div id='divFiledrop' class='dropArea'....

does the class gets supported by this method ?

Please have a look into wd_demo.au3, function DemoUpload. I guess this will answer or at least help you with your question 😀 .

Best regards
Sven

________________
Stay innovative!

Link to post
Share on other sites

Well if that is the case it seems , approach of Webdriver is going to be less useful for my case.

Because the first page is login credentials and which in my case I may not have, if others launches the executable.

Looking forward from response/confirmation from @mLipok or @Danp2

Is there any other way to achieve my requirement to upload files to existing webpage in firefox?

Edited by MakzNovice

It doesn't get easier, you just get better...

Link to post
Share on other sites

Hmm, get it,

10 minutes ago, MakzNovice said:

Because the first page is login credentials and which in my case I may not have, if user launches the executable.

Okay then maybe a non elegant way by mouse actions (moves) 🥴 in case you can not ask the user to enter credentials in forehand.

Just thinking about what you would do manually. You would click your file within a folder and "drag and drop" it to the Firefox window (into the drop area). When you arrange the Browser window size and position, this shouldn't be very flaky when it comes to execution on different monitor resolutions. But still ugly in my opinion.

Best regards
Sven

________________
Stay innovative!

Link to post
Share on other sites
24 minutes ago, MakzNovice said:

Because the first page is login credentials and which in my case I may not have, if others launches the executable.

So you have no right to do there anything?
 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2022-03-07

Link to post
Share on other sites

@SOLVE-SMART

That is what I tried in my first script, mouse clicks, but it won't work on firefox webpage :(

Really need to find a way as good as this _WD_SelectFiles.. if somehow can just crack a way to get handle of existing webpage... 

It doesn't get easier, you just get better...

Link to post
Share on other sites

@mLipok

It will work on my machine with my credentials, but would be problematic if other users use the script.

Also, I tried next steps manually and it takes almost 8-9 more steps to reach the page I need too...

Needless to say the page is dynamic, clicks are to be decided by other user actions... So its tough to automate logically till this page.

It doesn't get easier, you just get better...

Link to post
Share on other sites
1 minute ago, MakzNovice said:

It will work on my machine with my credentials, but would be problematic if other users use the script.

You should do one of the two things:
1. provide a way to put login/password by user to your program and thus to webpage.
2. open browser, display message to login manually, wait for login.... do the stuff.
 

2 minutes ago, MakzNovice said:

Also, I tried next steps manually and it takes almost 8-9 more steps to reach the page I need too...

and where is the problem ?

5 minutes ago, MakzNovice said:

Needless to say the page is dynamic, clicks are to be decided by other user actions... So its tough to automate logically till this page.

automate it tooo or: 2. open browser, display message to login manually, wait for login, wait for manually provided stuff .... do the automation stuff.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2022-03-07

Link to post
Share on other sites

@mLipok

Sorry I just confirmed one thing, I do not have option retrieve/ask for user credentials..

I am automating very small process of bigger tool, which has user already logged in and then this a part of internal operation.

- But seems webdriver approach is not going to work since we can't get existing page details..

Sorry again for my poor English which did not clarify that user credentials can't be requested.

It doesn't get easier, you just get better...

Link to post
Share on other sites

so only InternetExplorer..... :)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2022-03-07

Link to post
Share on other sites
3 hours ago, MakzNovice said:

1. I have my firefox session page already launched, how can I gets associate it Session created by _WD_CreateSession?

You cant unless the existing firefox instance was launched with Marionette enabled. See the following for more details --

4 hours ago, MakzNovice said:

In _WD_SelectFiles($sSession, $sStrategy, $sSelector, $sFilename) , what types of drop are supported As per documentation of method -   $sSelector - Value to find. Should point to element of type '< input type="file" >' The information that I have about by drop location by developer tools is - <div id='divFiledrop' class='dropArea'....does the class gets supported by this method ?

As you noted, _WD_SelectFiles is designed to work with a specific type of element, so it likely will not work with your target.

 

Link to post
Share on other sites

Hi MakzNovice,

here is a working example of pure mouse and window drag and drop usage which works also for Firefox.

Spoiler
; opt --------------------------------------------------------------------------
Opt('MouseCoordMode', 0)
Opt('MustDeclareVars', 1)
Opt('WinTitleMatchMode', 2)



; declaration ------------------------------------------------------------------
Global $sTitle                 = 'FileUploadDemo'
Global $sTargetFolderOfFiles   = @TempDir & '\' & $sTitle & '\'

Global $iFolderWindowWidth     = 500
Global $iFolderWindowHeight    = 500

Global $iSearchRectangleLeft   = 166
Global $iSearchRectangleTop    = 196
Global $iSearchRectangleRight  = 472
Global $iSearchRectangleBottom = 443
Global $vSearchColor           = 0xCCE8FF

Global $iTargetXPosition       = 3200
Global $iTargetYPosition       = 492



; processing -------------------------------------------------------------------
DirCreate($sTargetFolderOfFiles)

_writeFile($sTargetFolderOfFiles & 'file1.txt', 'Demo purpose 1')
_writeFile($sTargetFolderOfFiles & 'file2.txt', 'Demo purpose 2')
_writeFile($sTargetFolderOfFiles & 'file3.txt', 'Demo purpose 3')

_openFolder($sTargetFolderOfFiles)
_setExplorerFolderWindowPosition()
_selectFirstFileInOpenedFolder()
_dragAndDropByPixelColor()



; functions --------------------------------------------------------------------
Func _writeFile($sFile, $sText)
    Local Const $iUtf8WithoutBomAndOverwriteCreationMode = 256 + 2 + 8

    Local $hFile = FileOpen($sFile, $iUtf8WithoutBomAndOverwriteCreationMode)
    FileWrite($hFile, $sText)
    FileClose($hFile)
EndFunc

Func _openFolder($sFolderPath = @DesktopDir)
    ShellExecute($sFolderPath)
EndFunc

Func _setExplorerFolderWindowPosition()
    WinActivate($sTitle)
    WinWaitActive($sTitle, '', 2)
    WinMove($sTitle, '', 0, 0, $iFolderWindowWidth, $iFolderWindowHeight)
EndFunc

Func _selectFirstFileInOpenedFolder()
    Send('{DOWN}')
    Sleep(100)
    Send('{UP}')
EndFunc

Func _dragAndDropByPixelColor()
    Sleep(1000)

    Local $aCoordinates   = PixelSearch($iSearchRectangleLeft, $iSearchRectangleTop, $iSearchRectangleRight, $iSearchRectangleBottom, $vSearchColor)
    Local $iOffset        = 5
    Local $iFromXPosition = $aCoordinates[0] + $iOffset
    Local $iFromYPosition = $aCoordinates[1] + $iOffset

    _mouseDragAndDrop($iFromXPosition, $iFromYPosition, $iTargetXPosition, $iTargetYPosition)
EndFunc

Func _mouseDragAndDrop($iFromX, $iFromY, $iToX, $iToY, $iSpeed = 30)
    ;~ MouseClickDrag() isn't working, that's why I add this function

    Local $sMouseKey = 'primary'

    MouseMove($iFromX, $iFromY, $iSpeed)
    MouseDown($sMouseKey)

    MouseMove($iToX, $iToY, $iSpeed)
    MouseUp($sMouseKey)
EndFunc

 

I don't like it and would stick with WebDriver, but this could help 😅 . I guess you have to improve and adjust this example to fit your needs, but it works.

By the way @Danp2, thanks for the hint about Marionette. I wasn't aware of this by now - interesting 👍 .

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART
Link to post
Share on other sites

@SOLVE-SMART

Yes it indeed fit my requirement, quick and effective fix for long term problem.

I had to change my program to meet my needs as you mentioned.

I made it slightly more robust by skipping pixel search and instead using approach of source and target Top-Left corner coordinates (WinGetPos) + relative target location to finalize my X and Y.

Also confirmed that Firefox window will be 100% zoom. so chances of error are reduced. 

My code for reference

#include <MsgBoxConstants.au3>

Opt('MouseCoordMode', 0)
Opt('MustDeclareVars', 1)
Opt('WinTitleMatchMode', 2)

; declaration ------------------------------------------------------------------
Global $sTitle                 = 'FileUploadDemo'
Global $sTargetFolderOfFiles   = @TempDir & '\' & $sTitle & '\'

Global $iFolderWindowWidth     = 200
Global $iFolderWindowHeight    = 200

Global $iFileExplorerFile1X     = 61
Global $iFileExplorerFile1Y     = 114

Global $iFileExplorerFile2X     = 61
Global $iFileExplorerFile2Y     = 134

;~ Cordinates for
Global $iTargetXPosition1       = 75
Global $iTargetYPosition1       = 274

Global $iTargetXPosition2       = 175
Global $iTargetYPosition2       = 274

Global $sTitleString = "Mozilla Firefox"
Global $hWndExplorer, $hWndFF

; processing -------------------------------------------------------------------
DirCreate($sTargetFolderOfFiles)

_writeFile($sTargetFolderOfFiles & 'file1.txt', 'upload file 1')
_writeFile($sTargetFolderOfFiles & 'file2.txt', 'upload file 2')

_openFolder($sTargetFolderOfFiles)
_setExplorerFolderWindowPosition()
_setFireFoxWindowActive()

_selectFirstFileInOpenedFolder()
_dragAndDropByPixelColor()
;~ WinClose($hWndExplorer) ; Explorer window will be closed after work is done

; functions --------------------------------------------------------------------
Func _writeFile($sFile, $sText)
    Local Const $iUtf8WithoutBomAndOverwriteCreationMode = 256 + 2 + 8
    Local $hFile = FileOpen($sFile, $iUtf8WithoutBomAndOverwriteCreationMode)
    FileWrite($hFile, $sText)
    FileClose($hFile)
EndFunc

Func _openFolder($sFolderPath = @DesktopDir)
    ShellExecute($sFolderPath)
EndFunc

Func _setFireFoxWindowActive()
    If ProcessExists("Firefox.exe") Then
    $hWndFF = WinGetHandle($sTitleString)
    WinActivate($hWndFF)
Else
    MsgBox(64,"Error","No Firefox window found, closing script")
    Exit
EndIf
EndFunc

Func _setExplorerFolderWindowPosition()
    $hWndExplorer = WinGetHandle($sTitle)
    WinActivate($sTitle)
    WinWaitActive($sTitle, '', 2)
    WinMove($sTitle, '', 0, 0, $iFolderWindowWidth, $iFolderWindowHeight)
EndFunc

Func _selectFirstFileInOpenedFolder()
    WinActivate($hWndExplorer)
    Send('{DOWN}')
    Sleep(100)
    Send('{UP}')
EndFunc

Func _dragAndDropByPixelColor()
    Sleep(1000)

    ;~ PixelSearch is not suitable for my need, lets use WinGetPos
    ;Local $aCoordinates1   = PixelSearch($iSearchRectangleLeft, $iSearchRectangleTop, $iSearchRectangleRight, $iSearchRectangleBottom, $vSearchColor)
    
    ;MsgBox(64, "", "X and Y are: " & $aCoordinates[0] & "," & $aCoordinates[1])
    ;Local $iOffset        = 5
    WinActivate($hWndExplorer)
    Local $aPosExplorer = WinGetPos($hWndExplorer)

    ;Display the array values returned by WinGetPos.
    MsgBox($MB_SYSTEMMODAL, "Explorer details", "X-Pos: " & $aPosExplorer[0] & @CRLF & _
            "Y-Pos: " & $aPosExplorer[1] & @CRLF & _
            "Width: " & $aPosExplorer[2] & @CRLF & _
            "Height: " & $aPosExplorer[3]& @CRLF, 1)
    $iFileExplorerFile1X = $aPosExplorer[0] + $iFileExplorerFile1X
    $iFileExplorerFile1Y = $aPosExplorer[1] + $iFileExplorerFile1Y

    Sleep(1000)
    WinActivate($hWndFF)
    Local $aPos = WinGetPos($hWndFF)

    ; Display the array values returned by WinGetPos.
    MsgBox($MB_SYSTEMMODAL, "FireFox Window details", "X-Pos: " & $aPos[0] & @CRLF & _
            "Y-Pos: " & $aPos[1] & @CRLF & _
            "Width: " & $aPos[2] & @CRLF & _
            "Height: " & $aPos[3]& @CRLF, 1)

    $iTargetXPosition1 = $aPos[0] + $iTargetXPosition1
    $iTargetYPosition1 = $aPos[1] + $iTargetYPosition1
    WinActivate($hWndExplorer)
    _mouseDragAndDrop($iFileExplorerFile1X, $iFileExplorerFile1Y, $iTargetXPosition1, $iTargetYPosition1)

EndFunc

Func _mouseDragAndDrop($iFromX, $iFromY, $iToX, $iToY, $iSpeed = 30)
    ;~ MouseClickDrag() isn't working, that's why I add this function

    Local $sMouseKey = 'primary'

    MouseMove($iFromX, $iFromY, $iSpeed)
    MouseDown($sMouseKey)

    MouseMove($iToX, $iToY, $iSpeed)
    MouseUp($sMouseKey)
EndFunc

I will keep hunting for better solution including webdriver approach, but this is good workaround for me.

Any further support will be appreciated.

It doesn't get easier, you just get better...

Link to post
Share on other sites

Hi @MakzNovice,

1 hour ago, MakzNovice said:

Yes it indeed fit my requirement, quick and effective fix for long term problem.

That's great 😀, I am glad it was helpful.
Don't be shy or don't hesitate to press one of the fancy buttons here in case you want to.

ThanksOrLike.png.1d3e55b0c270582a9afd4aa52a1831af.png

I am not focused in getting any praise, it's more a gentle way of saying thanks for your invested time 😊 .

More important:

1 hour ago, MakzNovice said:

I made it slightly more robust [...]

I hoped that you will do this 👍 . Nice that you could get rid of the PixelSearch mechanism.

1 hour ago, MakzNovice said:

I will keep hunting for better solution including webdriver approach, but this is good workaround for me.

Yes please do so, because the WebDriver approach is such a flexible way of doing browser interactions which will help in many cases.

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ahha
      I'm using Firefox however it shows up in all browsers.  When you hover over a hyperlink and the cursor turns to a hand then in the lower left corner of the browser the actual web URL link pops up.  How does one capture that text programmatically?  I know in FF I can right click and "Copy Link" I'm wondering if there is another way.
    • By goldstar
      hey . is it possible  send message to firefox extension  and receive too?
      what is simplest way 
       
    • By mLipok
      wd_capabilities.au3 UDF was changed/modified/refactored .... and commited/merged (02-12-2021) to https://github.com/Danp2/WebDriver

      WARNING: Before you start using this UDF be sure you download the recent version from: https://github.com/Danp2/WebDriver
       
      ==================================================================================================

      Recently I start wd_capabilities.au3 project on my side.
      I think this is time to share to AutoIt community.
      Check attached UDF: wd_capabilities.au3

      Here is a scratch example showing how to use them:
      #include "wd_helper.au3" #include "wd_capabilities.au3" _Example() Func _Example() ........ ........ ........ _WD_Capabilities_Build_Arguments(Null) ; CLEANUP ARGS _WD_Capabilities_Build_Arguments('--headless') _WD_Capabilities_Build_Arguments('start-maximized') _WD_Capabilities_Build_Arguments('disable-infobars') _WD_Capabilities_Build_Arguments('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default') Local $s_WD_Capabilities_Arguments = _WD_Capabilities_Build_Arguments(Default) ; GET ARGS _WD_Capabilities_Build_Preferences(Null) ; CLEANUP PREFS If $s_Download_dir Then _WD_Capabilities_Build_Preferences('download.default_directory', $s_Download_dir) Local $s_WD_Capabilities_Preferences = _WD_Capabilities_Build_Preferences(Default) ; GET PREFS Local $s_Desired_Capabilities = _WD_Capabilities_Build_JSON('chrome', $s_WD_Capabilities_Arguments, $s_WD_Capabilities_Preferences) Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities) ........ ........ ........ EndFunc  
      I plan to publish the code on GitHub.
      In the indefinite future, when the project becomes more functional, if @Danp2 accepts it, I hope it may be included in the main WebDriver UDF.

      I am waiting for yours feedback and help in the further development of this project.

      REMARK 1:
      As so far this UDF only supports GoogleChrome.
      Adding support for other browsers shouldn't be difficult, I just didn't need to.

      REMARK 2:
      For now, this project is working but still as a early BETA, so please do not discuss, ask questions, or post examples or snippets of code that pertain to any function of this UDF in other part of this forum, until it is found acceptable. Simply: discusion and tests only here in this topic.


      Regards,
      @mLipok
       
    • By noellarkin
      This is for those pages that seem to load when you use _FFOpenURL(), but they have a text saying "please wait while we load your page..." but according to _FFOpenURL() the page has loaded.  An example seen in popular sites is the Cloudflare page saying "Checking your browser before...". It's the opposite of pausing a script until an element is visible on a page. It takes Elements in the form of id, xpath or text search.
      Global $BrowserPort = 4242 Global $TimeOut = 60000 Global $LocalHost = "127.0.0.1" Func _FFWaitWhileElement($thiselement, $elementtype = "xpath", $timeoutms = 60000) _FFConnect($LocalHost, $BrowserPort, $TimeOut) Local $Element Local $ElementFound = 1 Local $TimeoutCountdown = 0 While $ElementFound <> 0 And $TimeoutCountdown < $timeoutms If $elementtype = "xpath" Then $Element = _FFXPath($thiselement) EndIf If $elementtype = "id" Then Local $ConstructXPath = ".//*[@id='" & $thiselement & "']" $Element = _FFXPath($ConstructXPath) EndIf ; MsgBox(0, "", $Element) Local $ElementXPathTextContent = _FFCmd("FFau3.xpath.textContent") ; MsgBox(0, "", $ElementXPathTextContent) Local $ElementXPathInnerHTML = _FFCmd("FFau3.xpath.innerHTML") ; MsgBox(0, "", $ElementXPathInnerHTML) If $ElementXPathTextContent = "_FFCmd_Err" Or $ElementXPathInnerHTML = "_FFCmd_Err" Then $ElementFound = 0 Else $ElementFound = 1 EndIf If $elementtype = "text" Then $ElementFound = _FFSearch($thiselement) ; MsgBox(0, "", $ElementFound) EndIf $TimeoutCountdown += 1000 _FFDisConnect() _FFConnect($LocalHost, $BrowserPort, $TimeOut) WEnd Return $ElementFound EndFunc _FFConnect($LocalHost, $BrowserPort, $TimeOut) _FFOpenURL("https://www.site.com/page", True) _FFWaitForElement("Please Wait...","text", 60000) MsgBox(0,"","Page finished loading") It's pretty simple, hope it helps some of you who are working with FF.au3 :)
    • By noellarkin
      So I was trying to write a function that can find a button (or any other XPath Element) and scroll the page + move the mouse to the location of the button.
      My logic for this was:
      1. get position of button using _FFGetPosition
      2. get inner dimensions of browser window and total dimensions of page
      3. divide total dimensions by inner dimensions to get number of page down operations
      4. use Mod() to get remaining pixels offset
      5. MouseMove() and add requisite offsets for Titlebar etc (what the +5 and +54 is for in the last line)
      Example Code:
      _FFConnect($LocalHost, $BrowserPort, $TimeOut) Local $Button = _FFXPath(".//*[@id='thisbutton']") Local $ButtonPosition = _FFGetPosition($Button) Local $ElementWidth = $ButtonPosition[0] Local $ElementHeight = $ButtonPosition[1] Local $InnerWidth = _FFCmd("window.content.innerWidth") Local $InnerHeight = _FFCmd("window.content.innerHeight") Local $PageWidth = _FFCmd(".body.offsetWidth") Local $PageHeight = _FFCmd(".body.offsetHeight") Local $PGDNNo = Int($ElementHeight/$InnerHeight) Local $PGDNMod = Mod($ElementHeight, $InnerHeight) ; MsgBox(0,"","$ElementX: " & $ElementWidth & @CRLF & "$ElementY: " & $ElementHeight) ; MsgBox(0,"","$InnerWidth: " & $InnerWidth & @CRLF & "$InnerHeight: " & $InnerHeight) ; MsgBox(0,"","$PageWidth: " & $PageWidth & @CRLF & "$PageHeight: " & $PageHeight) ; MsgBox(0,"",$PGDNNo) ; MsgBox(0,"",$PGDNMod) Local $iter = 1 While $iter <= $PGDNNo WinActivate($BrowserWindowClass,"") _FFCmd("window.content.scrollByPages(1)") $iter += 1 WEnd MouseMove($ElementWidth + 5, $PGDNMod + 54) This isn't working. In some cases, it's not doing the page down operation the number of times needed, or not accurately pinpointing the location. I think there may be something wrong with the logic I'm using. What am I doing wrong?
      Thanks.
       
×
×
  • Create New...