Jump to content
Danp2

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...!

Share this post


Link to post
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")]')

 

Share this post


Link to post
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"

 

Share this post


Link to post
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.

 

Share this post


Link to post
Share on other sites

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


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  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 *

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 * 

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 TaskScheduler

PDF Related:https://www.autoitscript.com/forum/topic/177368-how-to-get-reference-to-pdf-object-embeded-in-ie/ *

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 *

"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: 2020-09-20

Share this post


Link to post
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...?   

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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...!

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Hello,

  Regarding my question above...can I use the WebDriver 'session' that was established to create my embedded window?  so for example: 

Local $oIE = ObjCreate($sSession)

Thanks in advance...

Share this post


Link to post
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.

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jgladden
      Dan - thanks for all that you do - this stuff is great. 
      Hoping you can assist with an issue we are having now that we have moved to Windows 10/Server 2016. The Chrome interactions were working flawlessly until moving over. Now my code fails when attempting to create the session. As you can see, our Chrome install is not in a standard location but I have validated the path to the binary. I have attached some detail below including system info, console output and the chrome log detail. I have tried several recommendations that have seen in various forums but none have made a difference
      Any assistance you can give would be greatly appreciated. 
      Thanks in advance, 
      chrome_Details.txt
    • By Danp2
      Introduction
      This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.
      Requirements
      JSON UDF https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn
      WinHTTP UDF https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
      HtmlTable2Array UDF (optional) https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Edge WebDriver https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      See the wiki for details on the UDF --
      https://www.autoitscript.com/wiki/WebDriver
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
    • By Langmeister
      I am once again asking for your experienced assistance. If I open a website that uses notifications I am asked to allow or block them for that website after a few seconds. This notification pops up every time the page gets navigated to, even tho you have clicked on allow for several times. I am explicitly not searching for smth to get rid of "Chrome is being controlled by automated test sw". Instead I am searching for a line of script to disable all notifications by default: like here chrome://settings/content/notifications. 
      This is code should give you an example of what notifications I am talking about:
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://webradio.planetradio.de/") _WD_LoadWait($sSession)  
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By Langmeister
      Hi, I need help performing actions in Salesforce using IE. I used to complete tasks via MouseMove/MouseClick etc. on the Chrome application of SF, but unfortunately this only works for me and not my colleagues due to different positions of things etc. Being unable to get Webdriver UDF or Chromedriver running to interact with the code directly, I chose to look into the IE UDF. ATM I'm trying to tick a specific checkbox in SF which simply allows me to "select all checkboxes" at the same time. Applying the following code on a random website with checkboxes works just fine for me: (in this case selecting cheese checkbox)
      #include <IE.au3> Local $oIE = _IECreate("http://www.echoecho.com/htmlforms09.htm") Local $oSubmit = _IEGetObjByName($oIE, "option3") _IEAction($oSubmit, "click") _IELoadWait($oIE) But applying it to the Salesforce website it does exactly nothing and responds with these warnings/errors:
      The script is exactly the same, except for website and the input name tag of the desired checkbox being different.
      #include <IE.au3> Local $oIE = _IECreate("Corporate Salesforce URL") Local $oSubmit = _IEGetObjByName($oIE, "myPage:myForm:oliListBlock:oliListTable:j_id36") _IEAction($oSubmit, "click") _IELoadWait($oIE) As its working with random websites my guess is that there has to be something done to get it work with SF.
      Hope the more experienced SF+AutoIt pros can help me out here. Thanks in advance!
×
×
  • Create New...