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 post
Share on other sites
  • Replies 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This is the "General Help and Support" thread for the WebDriver UDF. The UDF itself can be downloaded here. So if you have any questions, suggestions or errors please post here.

Hello @GregEisenberg You need to do this: Local $oJsonRect=_WD_ElementAction($sSession, $sElements, 'rect') ConsoleWrite("!" & Json_Get($oJsonRect, "[x]") & @CRLF) ConsoleWr

Time ago I wrote a function to extract data from  the source HTML code of tables. https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ Seems that that fun

Posted Images

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

 

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
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
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()

 

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()

 

 

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

 

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

 

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()

 

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.

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

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

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 goku200
      I'm having an issue with my html paginated table. The script work as expected. It reads the html table and clicks on the Download button. However when it clicks on the next page its not iterating the items. instead it goes to the next URL from the spreadsheet and then iterates through the html table clicking the Download button and so on. Not sure why its doing that. I want it to click the next page and then continue iterating then after it has reached the end of the pagination go to the next url in the spreadsheet and repeat the process. Below is my script. Any help is appreciated 🙂
      HTML Table:
      <!doctype html> <html> <head> <meta charset="utf-8"> <title>Test</title> </head> <body> <span style="font-weight:bold; font-size:13px">12345</span> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td> <table width="100%" cellspacing="1" cellpadding="2" border="0"> <tbody> <tr> <td class="test">ID</td> <td class="test" width="100%" nowrap=""> Name</td> <td class="test" nowrap="">Test1 Name</td> <td class="test" nowrap="">Test Date</td> <td class="test" nowrap="">Test Default</td> <td class="test" nowrap="">Test Status</td> <td class="test" nowrap="">Test Format</td> <td class="test" colspan="4">Actions&nbsp;</td> </tr> <tr> <td class="test" align="center">1</td> <td class="test">Test1</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download1">Download</a></td> </tr> <tr> <td class="test" align="center">2</td> <td class="test">Test2</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download2">Download</a></td> </tr> <tr> <td class="test" align="center">3</td> <td class="test">Test3</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download3">Download</a></td> </tr> <tr> <td class="test" align="center">4</td> <td class="test">Test4</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022 </td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download4">Download</a></td> </tr> <tr> <td class="test" align="center">5</td> <td class="test">Test5</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download5">Download</a></td> </tr> <tr> <td class="test" align="center">6</td> <td class="test">Test6</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download6">Download</a></td> </tr> <tr> <td class="test" align="center">7</td> <td class="test">Test7</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download7">Download</a></td> </tr> <tr> <td class="test" align="center">8</td> <td class="test">Test8</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/19/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download8">Download</a></td> </tr> <tr> <td class="test" align="center">9</td> <td class="test">Test9</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">1/7/2022</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download9">Download</a></td> </tr> <tr> <td class="test" align="center">10</td> <td class="test">Test10</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">12/8/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download10">Download</a></td> </tr> <tr> <td class="test" align="center">11</td> <td class="test">Test11</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">12/5/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download11">Download</a></td> </tr> <tr> <td class="test" align="center">12</td> <td class="test">Test12</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">12/5/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download12">Download</a></td> </tr> <tr> <td class="test" align="center">13</td> <td class="test">Test13</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">12/5/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download13">Download</a></td> </tr> <tr> <td class="test" align="center">14</td> <td class="test">Test14</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download14">Download</a></td> </tr> <tr> <td class="test" align="center">15</td> <td class="test">Test15</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download15">Download</a></td> </tr> <tr> <td class="test" align="center">16</td> <td class="test">Test16</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download16">Download</a></td> </tr> <tr> <td class="test" align="center">17</td> <td class="test">Test17</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download17">Download</a></td> </tr> <tr> <td class="test" align="center">18</td> <td class="test">Test18</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download18">Download</a></td> </tr> <tr> <td class="test" align="center">19</td> <td class="test">Test19</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download19">Download</a></td> </tr> <tr> <td class="test" align="center">20</td> <td class="test">Test20</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download20">Download</a></td> </tr> <tr> <td class="test" align="center">21</td> <td class="test">Test21</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download21">Download</a></td> </tr> <tr> <td class="test" align="center">22</td> <td class="test">Test22</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download22">Download</a></td> </tr> <tr> <td class="test" align="center">23</td> <td class="test">Test23</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download23">Download</a></td> </tr> <tr> <td class="test" align="center">24</td> <td class="test">Test24</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download24">Download</a></td> </tr> <tr> <td class="test" align="center">25</td> <td class="test">Test25</td> <td class="test" nowrap="">Joe</td> <td class="test" nowrap="">11/29/2021</td> <td class="test" nowrap=""> Default </td> <td class="test" nowrap=""> Uploaded </td> <td class="test" nowrap=""> html </td> <td class="test"><a href="#Download25">Download</a></td> </tr> </tbody></table> </td></tr> </tbody></table> <table cellspacing="1" cellpadding="3" border="0"> <tbody><tr> <td valign="middle"> </td> <td valign="middle"> <select name="next"> <option value="1" selected="">Page 1 of 7 </option><option value="2">Page 2 of 7 </option><option value="3">Page 3 of 7 </option><option value="4">Page 4 of 7 </option><option value="5">Page 5 of 7 </option><option value="6">Page 6 of 7 </option><option value="7">Page 7 of 7 </option></select> </td> <td valign="middle"> <a href="Next">Next</a> </td> </tr> </tbody></table> </body> </html> Autoit script
      #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <Excel.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) Sleep(5000) _WD_LoadWait($sSession) Sleep(5000) _WD_Navigate($sSession, '') _WD_LoadWait($sSession) _WD_NewTab($sSession) $ArticleWindow = _WD_Window($sSession, 'window', '') _WD_LoadWait($sSession) sleep(5000) _ExcelFunction() Func _ExcelFunction() Local $oAppl = _Excel_Open() Local $sWorkbook = "C:\Users\<username here>\Downloads\table.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) For $i = 0 To UBound($aArray2) - 1 ;Skip from reading header columns Local $Skipline = 1 ;0==> first line Local $temprf $temprf &= $aArray2[$i] If @error Then ContinueLoop If $i < $Skipline Then ContinueLoop _WD_Window($sSession, 'Switch', '{"handle":"' & $ArticleWindow & '"}') sleep(500) _WD_Navigate($sSession, $aArray2[$i]) _WD_LoadWait($sSession) Sleep(2000) htmlTable() Next EndFunc Func htmlTable() $sTable = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table") _WD_HighlightElement($sSession, $sTable, 2) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[8]/a", $sElement, True) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $sElement1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $aArray11 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[1]", $sElement1, True) For $j = 0 to UBound($aArray11) - 1 ;Skip from reading header columns Local $Skipline = 0 ;0==> first line Local $temprf $temprf &= $aArray11[$j] If @error Then ContinueLoop If $j < $Skipline Then ContinueLoop $aArray11[$j] = _WD_ElementAction($sSession, $aArray11[$j], 'text') Next ;Finds the ID and places it in a variable Local $sElement10 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/span") $sValue = _WD_ElementAction($sSession, $sElement10, 'text') ;Finds the ID and places it in a variable Local $sElement11 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[1]") $sValue2 = _WD_ElementAction($sSession, $sElement11, 'text') For $i = 0 to UBound($aArray1) - 1 ;Find the table of all the IDs $sButton1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table") _WD_HighlightElement($sSession, $sButton1, 2) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[1]/tbody/tr/td/table/tbody") Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[8]/a", $sElement, True) _WD_HighlightElement($sSession, $aArray1, 2) $links = _WD_ElementAction($sSession, $aArray1[$i], 'click') Sleep(2000) FileMove('C:\Users\<username here>\Downloads\*.html', 'C:\Users\<username here>\Downloads\' & $sValue & "_r" & $aArray11[$i] & '.htm', 1) Next ;Click on Next Page Local $next = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/table[2]/tbody/tr/td[3]/a") _WD_ElementAction($sSession, $next, 'click') Sleep(2000) EndFunc _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "localhost:9222"} {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc  
    • 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/205553-webdriver-udf-help-support-iii/
      Previous support threads (Closed)
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
       
    • By SkysLastChance
      How should I be attempting to click this link?

      <span id="x2m8_R-s" class="s_22 s-text">Walk&nbsp;In</span> If I double click the Walk$nbsp;In the text reads Walk In.

      How can I search for this text? 
      I have tried a several  different ways with no luck. Here are a few;
      $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//span[text()="Walk${nbsp}In"]') $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[translate(text(), '\u00a0', ' ') = 'Walk In']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[contains(text(),'Walk In')]") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[contains(text(),'Walk&nbsp;In')]") Any help is appreciated as always. 
       
       
       
    • By mLipok
      wd_capabilities.au3 UDF was changed/modified/refactored .... and commited/merged (02-12-2021) to https://github.com/Danp2/WebDriver

      WARNING: Before you start using this UDF be sure you download the recent version from: https://github.com/Danp2/WebDriver
       
      ==================================================================================================

      Recently I start wd_capabilities.au3 project on my side.
      I think this is time to share to AutoIt community.
      Check attached UDF: wd_capabilities.au3

      Here is a scratch example showing how to use them:
      #include "wd_helper.au3" #include "wd_capabilities.au3" _Example() Func _Example() ........ ........ ........ _WD_Capabilities_Build_Arguments(Null) ; CLEANUP ARGS _WD_Capabilities_Build_Arguments('--headless') _WD_Capabilities_Build_Arguments('start-maximized') _WD_Capabilities_Build_Arguments('disable-infobars') _WD_Capabilities_Build_Arguments('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default') Local $s_WD_Capabilities_Arguments = _WD_Capabilities_Build_Arguments(Default) ; GET ARGS _WD_Capabilities_Build_Preferences(Null) ; CLEANUP PREFS If $s_Download_dir Then _WD_Capabilities_Build_Preferences('download.default_directory', $s_Download_dir) Local $s_WD_Capabilities_Preferences = _WD_Capabilities_Build_Preferences(Default) ; GET PREFS Local $s_Desired_Capabilities = _WD_Capabilities_Build_JSON('chrome', $s_WD_Capabilities_Arguments, $s_WD_Capabilities_Preferences) Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities) ........ ........ ........ EndFunc  
      I plan to publish the code on GitHub.
      In the indefinite future, when the project becomes more functional, if @Danp2 accepts it, I hope it may be included in the main WebDriver UDF.

      I am waiting for yours feedback and help in the further development of this project.

      REMARK 1:
      As so far this UDF only supports GoogleChrome.
      Adding support for other browsers shouldn't be difficult, I just didn't need to.

      REMARK 2:
      For now, this project is working but still as a early BETA, so please do not discuss, ask questions, or post examples or snippets of code that pertain to any function of this UDF in other part of this forum, until it is found acceptable. Simply: discusion and tests only here in this topic.


      Regards,
      @mLipok
       
    • By Hermes
      Hi, I am trying to select elements in print page (dialog window) for a specific web page. But when trying to do so, it looks like it does not allow me to do it.
      So far, this is what I have:
      _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "body") Local $mainpagebody = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "body") _WD_HighlightElement($sSession, $mainpagebody, 2) _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "img.print-button") Local $printbutton = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "img.print-button") _WD_ElementAction($sSession, $printbutton, 'click') _WD_LoadWait($sSession) Sleep(3000) _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "body") Local $printpagebody = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "body") _WD_HighlightElement($sSession, $printpagebody, 2) The script above highlights the main web page "body" element, then clicks a tag to print a specific part of the page, then it will open a print page window where i am trying to highlight the body of that print page - but it looks like it is dropping from the session because it opens up another chrome page chrome://print.
       
      Below is the output log:
      __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"body"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}} _WD_WaitElement ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"body"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/execute/sync; $sData={"script":"arguments[0].style='background: #FFFF66; border-radius: 5px; padding-left: 3px;'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}]} __WD_Post: StatusCode=200; ResponseText={"value":true}... _WD_ExecuteScript: {"value":true}... __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"img.print-link"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}} _WD_WaitElement ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"img.print-link"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element/eb9e4673-4dec-4d4c-be6a-b7967743394b/click; $sData={"id":"eb9e4673-4dec-4d4c-be6a-b7967743394b"} __WD_Post: StatusCode=200; ResponseText={"value":null}... _WD_ElementAction: {"value":null}... __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/execute/sync; $sData={"script":"arguments[0].style='background: #FFFF66; border-radius: 5px; padding-left: 3px;'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}]} __WD_Post: StatusCode=200; ResponseText={"value":true}... _WD_ExecuteScript: {"value":true}... __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/execute/sync; $sData={"script":"return document.readyState", "args":[]} __WD_Post: StatusCode=500; ResponseText={"value":{"error":"script timeout","message":"script timeout\n (Session info: chrome=92.0.4515.107)... __WD_Post ==> Webdriver Exception: {"value":{"error":"script timeout","message":"script timeout\n (Session info: chrome=92.0.4515.107)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00C63733+2504499]\n\tOrdinal0 [0x00BFC401+2081793]\n\tOrdinal0 [0x00B024F0+1058032]\n\tOrdinal0 [0x00B55685+1398405]\n\tOrdinal0 [0x00B45E83+1334915]\n\tOrdinal0 [0x00B54CDB+1395931]\n\tOrdinal0 [0x00B45D4B+1334603]\n\tOrdinal0 [0x00B222B4+1188532]\n\tOrdinal0 [0x00B23149+1192265]\n\tGetHandleVerifier [0x00DDFB8C+1512252]\n\tGetHandleVerifier [0x00E8B0DF+2214031]\n\tGetHandleVerifier [0x00CE4BC3+484211]\n\tGetHandleVerifier [0x00CE3E69+480793]\n\tOrdinal0 [0x00C0218D+2105741]\n\tOrdinal0 [0x00C066E8+2123496]\n\tOrdinal0 [0x00C06827+2123815]\n\tOrdinal0 [0x00C0FB73+2161523]\n\tBaseThreadInitThunk [0x75EB62C4+36]\n\tRtlSubscribeWnfStateChangeNotification [0x77C11B69+1081]\n\tRtlSubscribeWnfStateChangeNotification [0x77C11B34+1028]\n"}} _WD_ExecuteScript: {"value":{"error":"script timeout","message":"script timeout\n (Session info: chrome=92.0.4515.107)... _WD_ExecuteScript ==> Webdriver Exception: HTTP status = 500 _WD_LoadWait ==> Webdriver Exception __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"body"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}} _WD_WaitElement ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"body"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/execute/sync; $sData={"script":"arguments[0].style='background: #FFFF66; border-radius: 5px; padding-left: 3px;'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}]} __WD_Post: StatusCode=200; ResponseText={"value":true}... _WD_ExecuteScript: {"value":true}...  
      Is it even possible to select elements in print page?

×
×
  • Create New...