Jump to content

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"

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

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

 

Link to comment
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
Link to comment
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
Link to comment
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()

 

Link to comment
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()

 

 

Link to comment
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"] }}}}'

 

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

 

Link to comment
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()

 

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

Link to comment
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
Link to comment
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
Link to comment
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?
 

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

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...