Jump to content

WebDriver UDF - Help & Support


Recommended Posts

Hello,

  Just downloaded this UDF a couple of days ago...so now I'm in the process trying to learn it.  First of all, many thanks to @Danp2 for all the effort you have put into this...!  So far I am very impressed by this script.

  As I mentioned, I'm still trying to figure how to use this...so I have a couple of preliminary questions if I may...

  The following snippet is not working for me...I'm simply trying to get the 'text' within the <title> tag...it seems to find the tag without any problem, however the 'text' and 'rect' part returns an empty string...what am I doing wrong here?

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByTagName, 'title')  ;SEEMS TO WORK...
ConsoleWrite("'$sElement' name (TAG): " & _WD_ElementAction($sSession, $sElement, 'name') & @CRLF)  ;returns the string "title"
ConsoleWrite("'$sElement' text: " & _WD_ElementAction($sSession, $sElement, 'text') & @CRLF)  ;returns empty string...?
ConsoleWrite("'$sElement' rect: " & _WD_ElementAction($sSession, $sElement, 'rect') & @CRLF)  ;returns empty string...???

  Also what is the difference between these two commands...they seem to do the same thing...is there some advantage to using one over the other...?

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByTagName, 'title')
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//title')

  And finally (for now) is there a way to locate an element by its 'text'...?  For example if "123 Main Street" or "ABC Corporation" appears on a website someplace...can I use these strings in a "_WD_FindElement" command to return the element TAG they might appear within ("<h1>", "<h3>", "<p>", "<b>", etc)... ?

  I thank you in advance for anybody that can give me some guidance here and again thank you so much to @Danp2 for this contribution...!

Link to comment
Share on other sites

4 hours ago, Burgs said:

Also what is the difference between these two commands...they seem to do the same thing...is there some advantage to using one over the other...?

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByTagName, 'title')
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//title')

  And finally (for now) is there a way to locate an element by its 'text'...?  For example if "123 Main Street" or "ABC Corporation" appears on a website someplace...can I use these strings in a "_WD_FindElement" command to return the element TAG they might appear within ("<h1>", "<h3>", "<p>", "<b>", etc)... ?

I prefer the latter (XPath) because it is query tool, not just a collection. Using XPath can easily solve your last question.

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//title[contains(text(), "123 Main Street")]')

 

Link to comment
Share on other sites

5 hours ago, Burgs said:

  The following snippet is not working for me...I'm simply trying to get the 'text' within the <title> tag...it seems to find the tag without any problem, however the 'text' and 'rect' part returns an empty string...what am I doing wrong here?

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByTagName, 'title')  ;SEEMS TO WORK...
ConsoleWrite("'$sElement' name (TAG): " & _WD_ElementAction($sSession, $sElement, 'name') & @CRLF)  ;returns the string "title"
ConsoleWrite("'$sElement' text: " & _WD_ElementAction($sSession, $sElement, 'text') & @CRLF)  ;returns empty string...?
ConsoleWrite("'$sElement' rect: " & _WD_ElementAction($sSession, $sElement, 'rect') & @CRLF)  ;returns empty string...???

From the wd_test.au3 file's TestNavigation():

ConsoleWrite("Title=" & _WD_Action($sSession, 'title') & @CRLF)

I think you have to do it that way because it's in the head, not body. If you're looking for the text of an element in the body, you had it right....

_WD_Navigate($sSession, "http://google.com")
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='gb_P']") ;"Images" link at the upper right
$sValue = _WD_ElementAction($sSession, $sElement, 'text') ;gets the text content of the node/element
ConsoleWrite('$sValue = ' & $sValue & @CRLF) ;"Images"

 

Link to comment
Share on other sites

Howdy,

  Thank you for the reply @Decibel...  OK I didn't realize the <head> and <body> tags made a difference in returning the text of an element.  Also thanks for the information about how to return a specific string...I will test that soon.  That should be useful...thank you again.

  I am having another issue I would appreciate any information I can get from anybody kind enough to offer.  I'm using this UDF with Firefox.  In Firefox (and other browsers) when you download a file a small dialog box displays and prompts if you want to 'open' or 'save' the file.  Is there an easy way to use this UDF to automate this?  Ideally I would like the 'save' selected to some specific location on my system.  I don't really know if this dialog would represent an HTML element...or perhaps another window...?  Any ideas would be greatly appreciated since it would be extremely useful to automate (or perhaps even suppress) that dialog box so no user intervention is required to click a response to it.  I thank you in advance.

 

Link to comment
Share on other sites

IMHO gui automation for this window will be the only thing you can do.

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 * How to ask ChatGPT for AutoIt Codefor 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) * Show_Macro_Values.au3 *

 

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: 2023-04-24

Link to comment
Share on other sites

Thank you for the reply.  Not sure what you mean by 'gui automation'...that can mean different things.

I notice this UDF can run JavaScript commands...I have not experimented with that yet...might that be a way to go about it...?   

Link to comment
Share on other sites

@Burgs Probably you could handle it using the DesiredCapabilities. check here. (Firefox Example)

A good alternative is to use @mLipok's suggestion like this.

 

Saludos

Link to comment
Share on other sites

Thanks for the post suggestions...a lot of information there...

  I got to thinking about this and arrived at a more simple approach, however it could be workable...I thought maybe use the "WinList" command or perhaps the "WinGetClassList" if that is what would be necessary to return a list of existing windows that contain the string "Mozilla" or "Firefox"...then perhaps I could loop through the returned array to get the window 'title' and 'handle' of each window that meets the criteria...then I should (in theory) be able to automate the process of 'saving' a file through that dialog...does this seem like a reasonable approach that might resolve this issue...?  I thank you again. 

Regards

Link to comment
Share on other sites

Hi again,

  I created a little test in regards to what I mentioned in my post above...it all works well except for some reason the "WinGetClassList" does not work...even though I pass the proper handle of the window to the command it returns an empty string...???   Anybody have a suggestion why/how that could be...?

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Retrieve a list of window handles.
    Local $aList = WinList()

    ; Loop through the array displaying only visable windows with a title.
    For $i = 1 To $aList[0][0]
        If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
         if StringInStr(String($aList[$i][0]), "Mozilla") > 0 Then
            MsgBox($MB_SYSTEMMODAL, "", "Title: " & $aList[$i][0] & @CRLF & "Handle: " & $aList[$i][1])
         Local $hWnd = $aList[$i][1]
         Local $_Class_Moz = WinGetClassList($hWnd)
ConsoleWrite("WINDOWS $hWnd: " & $hWnd & @CRLF)
ConsoleWrite("WINDOWS CLASS NAME: " & $_Class_Moz & @CRLF)
         EndIf  ;'Title' contains the word "Mozilla"...ONLY show "FireFox" windows that are acitve...!
        EndIf
    Next
EndFunc   ;==>Example

Thanks again for any input.

Link to comment
Share on other sites

You could probably press OK in the Firefox Dialog window using something like this:


While WinExists("[CLASS:MozillaDialogClass]")
    WinActivate("[CLASS:MozillaDialogClass]")
    WinWaitActive("[CLASS:MozillaDialogClass]","",1)
    Sleep(500)
    Send("{ENTER}")
WEnd
 

 

Sorry for no using code tag my connection is unable to load it.

 

Saludos

Link to comment
Share on other sites

Thanks for the information,

  I will give that a try when I have a chance...is that ALWAYS the name of the class ("MozillaDialogClass") for the dialog window...?  That is why I was trying to get the name of the class using the "WinGetClassList" command...so I could pass the proper class name of the window...  thanks again, regards...!

Link to comment
Share on other sites

Greetings again,

  Is it possible to register 'events' using this UDF...?  I'd like to be able to do things like recognize a 'double click' and to 'copy' highlighted text within the browser to the 'clipboard'...using FireFox browser...possible? 

  Also I'd like to 'embed' the FireFox browser in the same way I have previously with IE...however i'm unsure how to create the 'object'.  With IE I was using "Shell.Explorer.2" as here (direct from manual docs):    

Local $oIE = ObjCreate("Shell.Explorer.2")

    ; Create a simple GUI for our output
    GUICreate("Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))
    GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    $idButton_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
    $idButton_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
    $idButton_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
    $idButton_Stop = GUICtrlCreateButton("Stop", 330, 420, 100, 30)

    GUISetState(@SW_SHOW) ;Show GUI

    $oIE.navigate("http://www.autoitscript.com")

Any information greatly appreciated...thanks in advance and regards.

Link to comment
Share on other sites

@JonnyQuy What you see is what is available at this time. ;)

I imagine the documentation will improve over time. If you have specific questions, feel free to ask here in this thread. A great way to learn any UDF is to examine the actual code and the available examples. In this case, you could also learn a lot by reviewing the W3C WebDriver specifications.

Link to comment
Share on other sites

@Burgs I don't believe the Webdriver specs deal with embedded browsers, so you would need to handle that on your own.

You can connect to an existing Firefox instance like this --

_WD_Option('Driver', '<Path to your driver>\geckodriver.exe')
_WD_Option('DriverParams', '--log trace --connect-existing  --marionette-port 2828')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

For that to work, the Firefox instance needs to be launched with Marionette  activated. You can read more about that here.

Link to comment
Share on other sites

Hello  I was doing some test with this great UDF and noticed an issue _WD_Timeouts.( I know you talked about this in Github but It still fail with chrome.)

so here's my two cents.

Both work with Gecko

_WD_Timeouts($sSession, '{"page Load":2000}')
_WD_Timeouts($sSession, '{"type":"page load","ms":2000}')

Only this work with ChromeDriver

 _WD_Timeouts($sSession, '{"type":"page load","ms":2000}')

 

Between Thank you so much for this great UDF @Danp2

Saludos

 

Link to comment
Share on other sites

14 hours ago, Danp2 said:

@JonnyQuy What you see is what is available at this time. ;)

I imagine the documentation will improve over time. If you have specific questions, feel free to ask here in this thread. A great way to learn any UDF is to examine the actual code and the available examples. In this case, you could also learn a lot by reviewing the W3C WebDriver specifications.

 

I have a full UDF, but when I run "Test" it does not open the browser, my english is not good

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...