Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

11 hours ago, corgano said:

Damnit, I literally just got it

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["user-data-dir=userData"] } }}}'

However using @scriptdir didn't work for me. simply having =userData worked though.

What about hving a persistent window and just re-attaching to it? any ideas?

Interesting find. I use this arg to use my own profile on my W7-64 PC:

"--user-data-dir=C:/Users/' & @UserName & '/AppData/Local/Google/Chrome/User Data"

Share this post


Link to post
Share on other sites

It seems that _WD_Alert() function does not detect a confirmation dialog box. The 'status' or 'gettext' command returns no value when a confirmation dialog box created by the following javascript is in place in a Chrome session created by _WD_CreateSession().

function send_memo()
    {
        var f = document.memoForm;
    
        str = "발송";
        if (!check_confirm(str))
            return;
    
        if (!confirm("선택한 회원에게 SMS 를 "+str+" 하시겠습니까?"))
            return;
    
        //var new_win = window.open('','send_memo','scrollbars=yes,width=600,height=600,top=10,left=20');
        //f.target = "send_memo";
        f.action = "cm_sms_form.php";
        f.method = "post";
        f.submit();
    }

Please help me on how to detect this dialog box.

Share this post


Link to post
Share on other sites

I don't know what I did wrong the last time, but now it works fine. Thank you for your attention. The actual web site requires sign-in, so I used following codes to simulate the situation. In the code, _WD_ElementAction($Session, $button, "click") did not work, so I forcefully clicked the link.

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities
$_WD_DEBUG = False
SetupChrome()
_WD_Startup()

$Session = _WD_CreateSession($sDesiredCapabilities)
Sleep(500)

_WD_Navigate($Session, 'file:///' & StringReplace(@ScriptDir, '\', '/') & '/Confirm_Dialog.html')
Sleep(500)

$button = _WD_FindElement($Session, $_WD_LOCATOR_ByClassName, "btn")
Sleep(500)

; MsgBox(0, '', $button)

; _WD_ElementAction($Session, $button, "click")
MouseClick("left", 150, 90)
Sleep(1000)

MsgBox(0, '', _WD_Alert($Session, "gettext"))


_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
<!-- Confirm_Dialog.html -->
<html>

    <div class="btn">
        <a href="javascript:send_memo();"><u>Click to Create a Confirmation Dialog Box</u></a>
    </div>


    <script language='Javascript'>
    function send_memo()
    {
        confirm("Can you detect this confirmation dialog box?")

    }

    </script>

</html>

 

Share this post


Link to post
Share on other sites

Hello I was needing to switch to a frame, I didn't find any topic talking about here  so I had to investigate, So This worked for me.

 

For chrome I used this (pass the frame id):

_WD_Window($sSession,'frame','{"id":"' & "here_the_frame_id" & '"}')

for firefox I need to use this way(here need to pass the element id like is return by GetElement):

_WD_Window($sSession, 'frame', '{"id": {"element-6066-11e4-a52e-4f735466cecf":"b3db7f30-5e1d-4d84-8d48-566cafa43893"}}')

 

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

Hello,

I'm new to WebDriver UDF and I'm trying to start a session with a previously opened session id. 

Can I use the session id of a previously opened chrome browser window for _WD_CreateSession? How can I specify the session id with $sDesiredCapabilities.

I have tried giving "sessionId":"ab4c66c0c0e573833b5dddc121680a7c" , with capabilities string but I do not know the correct syntax to follow.

Please help.

#include "wd_core.au3"
Local $sDesiredCapabilities
$_WD_DEBUG = true
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
;$DesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars"] }}}}'
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars"]}}}, "sessionId:""ab4c66c0c0e573833b5dddc121680a7c"}'
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
MsgBox(0,"",$sSession)
msgbox(0,"","URL=" & _WD_Action($sSession, 'url') & @CRLF)
msgbox(0,"","Title=" & _WD_Action($sSession, 'title') & @CRLF)
;_WD_DeleteSession($sSession)
;_WD_Shutdown()

 

Edited by PoojaKrishna

Share this post


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

@PoojaKrishna This was discussed recently in this thread. At this time, I'm not aware of a way to attach to an existing Chrome window.

Thank you for your reply.

I was trying to apply the default chrome profile while creating a new session, the code is attached below. It opens a new browser with the default profile but returns a blank session id for future reference. Please help me If I have used this parameter in a wrong way.

#include "wd_core.au3"
#RequireAdmin
Local $sDesiredCapabilities
$_WD_DEBUG = true
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
sleep(5000)
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars","user-data-dir=C:\\Users\\USER\\AppData\\Local\\Google\\Chrome\\User Data"] }}}}'
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
If $sSession <> "" Then
    MsgBox(0,"",$sSession)
    _WD_Navigate($sSession, "https://www.gmail.com/")
    msgbox(0,"","URL=" & _WD_Action($sSession, 'url') & @CRLF)
    msgbox(0,"","Title=" & _WD_Action($sSession, 'title') & @CRLF)
    ;msgbox(0,"",_WD_GetElementFromPoint($sSession, 810, 550))
Else
    msgbox(0,"","Blank sessionid")
EndIf

_WD_DeleteSession($sSession)
_WD_Shutdown()

 

Share this post


Link to post
Share on other sites

Closing all chrome instances before starting my webdriver script solved the problem. Let me know if anyone has a solution other than this. Thank you.

1 hour ago, PoojaKrishna said:

Thank you for your reply.

I was trying to apply the default chrome profile while creating a new session, the code is attached below. It opens a new browser with the default profile but returns a blank session id for future reference. Please help me If I have used this parameter in a wrong way.

#include "wd_core.au3"
#RequireAdmin
Local $sDesiredCapabilities
$_WD_DEBUG = true
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
sleep(5000)
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars","user-data-dir=C:\\Users\\USER\\AppData\\Local\\Google\\Chrome\\User Data"] }}}}'
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
If $sSession <> "" Then
    MsgBox(0,"",$sSession)
    _WD_Navigate($sSession, "https://www.gmail.com/")
    msgbox(0,"","URL=" & _WD_Action($sSession, 'url') & @CRLF)
    msgbox(0,"","Title=" & _WD_Action($sSession, 'title') & @CRLF)
    ;msgbox(0,"",_WD_GetElementFromPoint($sSession, 810, 550))
Else
    msgbox(0,"","Blank sessionid")
EndIf

_WD_DeleteSession($sSession)
_WD_Shutdown()

 

 

Share this post


Link to post
Share on other sites
2 hours ago, PoojaKrishna said:

I was trying to apply the default chrome profile while creating a new session, the code is attached below. It opens a new browser with the default profile but returns a blank session id for future reference. Please help me If I have used this parameter in a wrong way.

I saw the same behavior until I corrected the profile string --

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars","user-data-dir=C:\\Users\\USER\\AppData\\Local\\Google\\Chrome\\User Data\\Default"] }}}}'

 

Share this post


Link to post
Share on other sites

Can you please see the following link:

https://stackoverflow.com/questions/14480717/load-chrome-profile-using-selenium-webdriver-using-java

When we use a profile path like you have given, the opened chrome is not with the default profile.

To test, run the code and give,  'chrome://version/' on the address bar. You can find 

  C:\Users\USER\AppData\Local\Google\Chrome\User Data\Default\Default , as the profile path.

Share this post


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

Ok... that makes sense as to why it worked with that scenario. Thanks for the correction.

Still seems like a bug to me that the ChromeDriver fails to respond or give a proper session id.

Can you please look into this link for more information regarding the issue:

https://stackoverflow.com/questions/37317427/unable-to-move-the-cache-error-in-selenium-webdriver/37992070#37992070

 

Share this post


Link to post
Share on other sites

_WD_GetMouseElement($sSession)  and _WD_GetElementFromPoint($sSession, 810, 550) methods returns only a blank string. I have added these methods also to the wd_core.au3 header file.

Please let me know If any one has a suggestion to use these methods better. Thank you.

#include "wd_core.au3"
#RequireAdmin
Local $sDesiredCapabilities
$_WD_DEBUG = false
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
sleep(5000)
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars","--user-data-dir=C:/Users/USER/AppData/Local/Google/Chrome/User Data"] }}}}'
; $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars","user-data-dir=C:\\Users\\USER\\AppData\\Local\\Google\\Chrome\\User Data\\Default"] }}}}'
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
If $sSession <> "" Then
    MsgBox(0,"",$sSession)
    _WD_Navigate($sSession, "https://www.gmail.com/")
    msgbox(0,"","URL=" & _WD_Action($sSession, 'url') & @CRLF)
    msgbox(0,"","Title=" & _WD_Action($sSession, 'title') & @CRLF)
    msgbox(0,"",_WD_GetElementFromPoint($sSession, 810, 550))
    msgbox(0,"",_WD_GetMouseElement($sSession))
Else
    msgbox(0,"","Blank sessionid")
EndIf

;_WD_DeleteSession($sSession)
_WD_Shutdown()

 

Share this post


Link to post
Share on other sites
39 minutes ago, PoojaKrishna said:

I have added these methods also to the wd_core.au3 header file.

Why would you do that? It just creates a maintenance issue and also means your code won't work for other people.

Quote

_WD_GetMouseElement($sSession)  and _WD_GetElementFromPoint($sSession, 810, 550) methods returns only a blank string.

It works in FIrefox, but not Chrome. This is due to the fact that they return their results in different formats. I'll need to investigate to see which one is W3C-compliant and how easy it would be to support both formats.

Share this post


Link to post
Share on other sites

Yes fixed!!! Thank you so much for being so helpful.

Downloaded the new versions from Github and it worked. 

Quote

Why would you do that? It just creates a maintenance issue and also means your code won't work for other people.

Corrected.

Edited by PoojaKrishna

Share this post


Link to post
Share on other sites

So far this is working perfectly for what I need it for!
I do have a few questions though:
How can I retrieve a list from a specific element I find?
For instance, I'm trying to get the options from a select element.  I'm able to call FindElement without a problem, but when trying to find the options inside of it, that's when things come back empty:
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@id=DropDown]")
$sElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@id=DropDown]/option")

$sElement works whereas $sElements is empty

*EDIT
Also, I know this is probably a long shot, but would  be incredible:
Can the ExecuteScript function also work with JQuery? I tested it without luck but that would be amazing

 

Edited by dumdumpop

Share this post


Link to post
Share on other sites

@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?
 

Share this post


Link to post
Share on other sites

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

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