Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

6 hours ago, Danp2 said:

@dumdumpop A few different options here --

  1. Use _WD_ElementAction to retrieve the text after you've located the Select element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@id=DropDown]")
    $sText = _WD_ElementAction($sSession, $sElement, 'text')

     

  2. You could also try calling _WD_FindElement twice, where you pass the result from the first call into the second one --
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@id=DropDown]")
    $sElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//option", $sElement, True)

     

AFAIK, you should be able to use _WD_ExecuteScript to call just about any command or function that you desire. Can you provide a runnable snippet of code that demonstrates where the jQuery interaction was unsuccessful?
 

I just got the JQuery to work! This is absolutely incredible thank you!
*EDIT
I did notice one thing, when I try to retrieve a value, it comes back as null.  Is there a way to retrieve information from a JQuery script call?
ex: using a script like $('#ElementId').height()
I know I can probably get the information from the FindElement function, but just exploring possibilities right now :) 

Also both of what you sent ended up working perfectly, thank you so much!

6 hours ago, Danyfirex said:

Hello. You also could do this.

Local $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='DropDown']/option","",True)
;~ _ArrayDisplay($aElements)
For $i=0 to UBound($aElements)-1
    ConsoleWrite(_WD_ElementAction($sSession, $aElements[$i], 'text') & @CRLF)
    ConsoleWrite(_WD_ElementAction($sSession,$aElements[$i], 'attribute', 'value') & @CRLF)
Next

Saludos

This was exactly what I was hoping to get out of this too, thank you so much!

Edited by dumdumpop

Share this post


Link to post
Share on other sites
8 hours ago, dumdumpop said:

I did notice one thing, when I try to retrieve a value, it comes back as null.  Is there a way to retrieve information from a JQuery script call?
ex: using a script like $('#ElementId').height()

Did you forget to return the value?

_WD_ExecuteScript($sSession, "return $('#ElementId').height()")

 

Share this post


Link to post
Share on other sites
9 minutes ago, Danp2 said:

Did you forget to return the value?

_WD_ExecuteScript($sSession, "return $('#ElementId').height()")

 

A bit of a face-palm moment.  I didn't return it, just tested the return and works like a charm. Lol thanks again!

Share this post


Link to post
Share on other sites

Howdy,

  This is probably a simple question.  I'm using this great UDF with FireFox.  I have a 'main' window setup without any problems.  My question is how can I get a 'new tab' windows opened up properly?  When I attempt to do so the new tab itself opens without any problem...however I cannot get it to navigate to a URL...?

 

Global Const $_TestType = $eFireFox
Global $sDesiredCapabilities
Global $iIndex
Global $sSession
Global $sElement

$_WD_DEBUG = True

 Switch $_TestType
     Case $eFireFox
         SetupGecko()
        
     Case $eChrome
         SetupChrome()
  
 EndSwitch
 
 _WD_Startup()
 
 $sSession = _WD_CreateSession($sDesiredCapabilities)
 
 $oIE2 = _WD_Navigate($sSession, "https://www.google.com")
 
 ;;;;;ABOVE ALL WORKS FINE...I TRY TO CREATE A NEW 'TAB'...
 
 Local $_URL_TAB = _WD_NewTab($sSession, False)  ;opens a new tab no problem
 _WD_Navigate($_URL_TAB, "http://www.nfl.com")  ;new tab does not navigate anywhere...?

  I get an "invalid session id" error...?  

I was under the impression that the '_WD_NewTab' creates a handle to be used to control the navigation in the new tab...what am I not understanding here?  Thanks in advance for any advice.  Regards.

 

Edited by Burgs

Share this post


Link to post
Share on other sites

You need to switch to the tab(window) so just set the switch parameter to true in NewTab Function. 

 

Local $hNewTabWindow = _WD_NewTab($sSession, True)
ConsoleWrite($hNewTabWindow & @CRLF)
_WD_Navigate($sSession, "https://www.google.com")

 

Saludos

Share this post


Link to post
Share on other sites
6 hours ago, Burgs said:

I was under the impression that the '_WD_NewTab' creates a handle to be used to control the navigation in the new tab...what am I not understanding here?  Thanks in advance for any advice.  Regards.

The handle returned by _WD_NewTab is not a session ID, so it can't be used in that manner. Either change the $iSwitch parameter to True as shown above or you can manually switch to any tab like this --

_WD_Window($sSession, 'Switch', '{"handle":"' & $YOUR_TAB_HANDLE_GOES_HERE & '"}')

 

Share this post


Link to post
Share on other sites

Hello

Chrome web driver closes after ruuning wd_test.au3

  • Win10 Home x64 
  • Chrome 67.0.3396.99 x64
  • chromedriver.exe v2.40 x32 (latest)
  • autoit 3.3.14.5

Console otput:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\_Projects\ltb\wd_test.au3"    
_WDStartup: OS:    WIN_10 WIN32_NT 17134 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.10
_WDStartup: Driver:    chromedriver.exe
_WDStartup: Params:    --log-path="C:\_Projects\at\chrome.log"
_WDStartup: Port:    9515
_WD_Startup ==> General Error: Error launching web driver!
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_CreateSession: 0
_WD_CreateSession ==> Webdriver Exception: HTTP status = 0
Bypass: TestTimeouts
Bypass: TestNavigation
Bypass: TestElements
Bypass: TestScript
Bypass: TestCookies
Bypass: TestAlerts
Running: TestFrames
__WD_Post: URL=HTTP://127.0.0.1:9515/session//url; $sData={"url":"https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols"}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_Navigate: 0
_WD_Navigate ==> Webdriver Exception: HTTP status = 0
__WD_Post: URL=HTTP://127.0.0.1:9515/session//execute/sync; $sData={"script":"return window.frames.length", "args":[[]]}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_ExecuteScript: 0
Frames=0
__WD_Post: URL=HTTP://127.0.0.1:9515/session//execute/sync; $sData={"script":"return window.top == window.self", "args":[[]]}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_ExecuteScript: 0
TopWindow=
__WD_Post: URL=HTTP://127.0.0.1:9515/session//element; $sData={"using":"xpath","value":"//iframe[@id='iframeResult']"}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_FindElement: 0
_WD_FindElement ==> Send / Recv error: HTTP status = 0
__WD_Post: URL=HTTP://127.0.0.1:9515/session//frame; $sData={"id":{"element-6066-11e4-a52e-4f735466cecf":""}}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_Window: 0
__WD_Post: URL=HTTP://127.0.0.1:9515/session//execute/sync; $sData={"script":"return window.top == window.self", "args":[[]]}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_ExecuteScript: 0
TopWindow=
__WD_Post: URL=HTTP://127.0.0.1:9515/session//frame/parent; $sData={}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_Window: 0
__WD_Post: URL=HTTP://127.0.0.1:9515/session//execute/sync; $sData={"script":"return window.top == window.self", "args":[[]]}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_ExecuteScript: 0
TopWindow=
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/
__WD_Delete: StatusCode=0; ResponseText=0
__WD_Delete ==> Webdriver Exception
_WD_DeleteSession: 0
_WD_DeleteSession ==> Webdriver Exception: HTTP status = 0
>Exit code: 0    Time: 13.46

Share this post


Link to post
Share on other sites

Danp2,

OK great, thanks for the information...I believe I understand now...will try that later today.  Regards.

Share this post


Link to post
Share on other sites

Danp2, Hello again!

I figured out how to search for items with id, for example, entering data into the search window and pressing a button. But I still did not understand how to search for the elements as described below.

How to find element by its text, for ex: Gmail Mail button.
image.thumb.png.f1853ec130c2cb945e12533d39470287.png

Share this post


Link to post
Share on other sites

Hello @slvtn666 You can do this:

 

local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'hereyourtext')]")

Saludos

Share this post


Link to post
Share on other sites
3 minutes ago, Danyfirex said:

Hello @slvtn666 You can do this:

 

local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'hereyourtext')]")

Saludos

Thank you for your reply

Im getting following error:

__WD_Post: URL=HTTP://127.0.0.1:9515/session/aefbbec49c57a7d1e651158e92175521/element; $sData={"using":"xpath","value":"//*[contains(text(),'��)]"}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_FindElement: missing command parameters
_WD_FindElement ==> Webdriver Exception: HTTP status = 400

Share this post


Link to post
Share on other sites

You need to add the last single quoted after the search  text.

 

 

Saludos

Share this post


Link to post
Share on other sites
23 minutes ago, Danyfirex said:

You need to add the last single quoted after the search  text.

 

 

Saludos

image.thumb.png.19427fffc211534b8c1c8f68ed57b032.png

 

Idk... may be the trouble in cyrillic symbols?

Edited by slvtn666

Share this post


Link to post
Share on other sites

Thank for udf

I have simple code here: 

#include "wd_core.au3"
    
Local $url = "http://google.com/"
Local $sDesiredCapabilities
SetupChrome()
_WD_Startup()
$Session = _WD_CreateSession($sDesiredCapabilities)
Sleep(2000)
_WD_Navigate($Session, $url)
    _WD_Shutdown()
    
Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path=' & @ScriptDir & '\chrome.log')
        $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars"] }}}}'
EndFunc

When I run this code, New profile chrome open. So I can't see account gmail and browser history. But I want keep it. How can i do this? Thank you ..

 

Share this post


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

When I run this code, New profile chrome open. So I can't see account gmail and browser history. But I want keep it. How can i do this? Thank you ..

This is the default behavior, so you need to override this as discussed recently in this same thread.

 

Share this post


Link to post
Share on other sites

Hello

  Sorry I need a clarification to my above post.  I was able to create new 'tab' windows without any problem.  However it seems when this is done the new 'tab' has the focus...?  In my code I use the main "sSession" window to scrape some necessary data from that page's HTML...however when I create the 'tab' window I lose that functionality...it seems that my code is then trying to scrape the HTML from the 'tab' window instead of the 'main' ('sSession') window...

  How would I go about 'resetting' the focus back to the 'main' ('sSession') browser window again after each tab(s) are created?  for example:

_WD_Window($sSession, 'Switch', '{"handle":"' & $YOUR_TAB_HANDLE_GOES_HERE & '"}')  ;as stated above this will 'switch' tabs

;therefore...?

_WD_Window($sSession, 'Switch', '{"handle":"' & $sSession & '"}')  ;would be used to 'reset' focus back to the 'main' browser window?

Is that syntax correct ?  I only question it because the main browser seems to call itself...?  It is difficult for me to test this right now because of some Internet connectivity issues...I thank you in advance for any help.  Regards.

Share this post


Link to post
Share on other sites

Like I stated before, Session ID and Tab Handle are not interchangeable. You can get the current tab handle with this --

$current_tab = _WD_Window($sSession, 'Window')

Once you have that, then you would use this value to switch back to this tab at any time --

_WD_Window($sSession, 'Switch', '{"handle":"' & $current_tab & '"}')

Otherwise, you can use _WD_Attach to switch to a given tab.

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