Jump to content

WebDriver UDF - Help & Support


Recommended Posts

39 minutes ago, Hamburgo said:

I posted the command that I am figured out to send keystrokes. Do you know a better way ?

That command is designed to update the value of an element. YMMV when used in the manner you describe.

44 minutes ago, Hamburgo said:

Only ctrl+f will not do his job and will not open the search-field of FireFox. Do you know a reason ?

Probably because the keystroke is being handled at the element level rather than the browser level. Depending on your goal, either of the following should work --

  • Use _WD_ExecuteScript to execute the javascript command find(), ie:
    $result = _WD_ExecuteScript($sSessionID, "return find('yourstringhere')")
  • Send the keystroke to the browser rather than the element. Now were back to the advanced feature with little documentation. Here's a hint if you choose to go this route --
    https://github.com/nicholaswmin/webdriver-actions
Link to comment
Share on other sites

@Danp2 Do you know how can I search a-tag by href='SearchString' if the SearchString has inside UTF8-Characters like the german once ?

for example:

$sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='#löhne_&_gehälter']")

$sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='#l%C3%B6hne_&_geh%C3%A4lter']")

The _WD_FindElement-Function did not find any of this two strings.

Link to comment
Share on other sites

Good evening Danp2, 

First, I wanted to thank you and the team for creating this awesome tool. I feel like I missed the party but glad I am outside knocking on the door to get in. Second, once I get this script working you and the team have helped save 10 high school teachers about 100+ hours worth of work a piece. So again, thank you.

Please let me know if I have posted this question into the wrong forum.

I am trying to figure out how to get the innerhtml from certain tags after the Canvas Module on the page is created.

Spoiler
<button class="btn al-trigger" aria-label="Manage Installation: Foundation &amp; Subflooring" aria-haspopup="true" aria-owns="ui-id-2" tabindex="0">
          <i class="icon-more" aria-hidden="true"></i>
</button>

 

What I am trying to get is the "Manage Installation: Foundation & Subflooring" from the aria-label. 

Project Information

Spoiler
#comments-start

Author:                 Thomas E. Bennett
E-mail:                 thomas.bennett@sfisd.org
Original Creation Date: 03/30/2019
Browser:                Google Chrome
Version:                73.0.3683.86 (Official Build) (64-bit)

Script Function
    To automate functions in Canvas; this is to assist with the creation of Canvas modules, assignments in said modules, and
    to link to the iCEV External App found in Canvas. 
    ** Login to Canvas                                                          -- DONE! (03/30/2019)
    ** Read from a .csv file to create Canvas Modules and Assignments           -- DONE! (03/30/2019)
    ** Create a Canvas Module from the file                                     -- DONE! (03/30/2019)
    ** Publish the Canvas Module                                                -- DONE! (03/31/2019)
    ** Verification that the correct Canvas Module is being manipulated         -- IN PROGRESS
    ** Set Unlock date on Canvas Module                                         -- IN PROGRESS
    ** Set Pre-reqs on Canvas Module                                            -- IN PROGRESS
    ** Create Assignments in Canvas Module                                      -- IN PROGRESS
    ** Connect the Assignment to the iCEV External App                          -- IN PROGRESS
    ** Set Requirements for Canvas Module                                       -- IN PROGRESS

#comments-end

 

Current Code

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

; Variables / Constants
Local $sSession, $sDesiredCapabilities, $sURL, $sPassword, $sUsername, $sText, $iTime

; Open the file below
Local $file = FileOpen("curriculum.csv", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error: Unable to open file.", "The file must be with the executable.")
    Exit
EndIf

$sURL = "gladirememberedtoclearthis"
$sUsername = "gladirememberedtoclearthis"
$sPassword = "gladirememberedtoclearthis" ; When publishing clear this line completely! I know it is unsafe to do. :P
$iTime = 5000

SetupChrome()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

; Go to website
_WD_Navigate($sSession, $sURL)

; Enter username and password
_ChromeSetInputValueById($sSession,"pseudonym_session_unique_id",$sUsername)
_ChromeSetInputValueById($sSession,"pseudonym_session_password",$sPassword)

; Login
$sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='Button Button--login']")
_WD_ElementAction($sSession, $sButton, 'click')

; Go to specific course

While 1
    ; Read the .csv file
    Local $line = FileReadLine($file)
    If @error = -1 Then ExitLoop

#comments-start

While reading the .csv file split the string information based on the , delimiter
$line_split[array number] will display different information from the .csv file
This is dependent upon how the .csv file information is setup of course
$line_split[1] = COURSE NAME {CASE SENSITIVE}
$line_split[2] = NAME OF MODULE
$line_split[3] = UNLOCK DATE
$line_split[4] = NAME OF ASSIGNMENT
$line_split[5] = WEIGHT {CASE SENSITIVE} {DAY, MIN, MAJ} Daily, Minior, Major Grade
$line_split[6] = DUE DATE

Changing the _WD_FindElements to search by location on the screen; this should help control
which module is being modified. I need to add some logic to get the name of the module, check
the name in the row in the text file being read, and then snag the "location" path or number

Need to figure out the _WD_ version of Sleep; this will cause the script to pause until the
needed element has shown up on the page (in the code)

#comments-end

    Local $line_split = StringSplit($line, ',', 1)

    ; Stripping all spaces out of the String
    ;$line_split[1] = StringStripWS($line_split[1], 8)

    ; Wait for the page to load; if the button hasn't rendered yet; it never gets clicked on.
    ; This really should be dynamic a static 5 second pause isn't good form.
    Sleep ($iTime)

    ; Name of the Course the program needs to go into
    $sText = $line_split[1]

    _WD_LinkClickByText($sSession, $sText)

    Sleep ($iTime)

    ; Click the "+Module" button
    $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[3]/div/div/button")
    _WD_ElementAction($sSession, $sButton, 'click')

    ; Name the module
    $sText = $line_split[2]
    $sInput = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//form/div/div/div/input")
    _WD_ElementAction($sSession, $sInput, 'value', $sText)

    ; Click the "Add Module" button
    $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='btn btn-primary submit_button']")
    _WD_ElementAction($sSession, $sButton, 'click')

    Sleep ($iTime)
    
    #comments-start
    
    ** Create verification that the correct areas are being selected            -- IN PROGRESS
      * Find the recently created Module
      * Look for a div class named "item-group-condensed context_module editable_context_module" with an aria-label that matches
        the name of the recently created Module
      * Get the data-module-id of this matching aria-label
      * 
    ;Find the recently created Module dynamically
    ;This is critically important for Module and Assignment creation
    ;Look for a div class named "item-group-condensed context_module editable_context_module" with an aria-label equal
    
    #comments-end
    

    ; Click the "Publish" button
    ;$sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@class='publish-icon module unpublished publish-icon-publish']")
    $sButton = _WD_FindElement ($sSession, $_WD_LOCATOR_ByXPath, "//div[2]/div/div[3]/span/i")
    _WD_ElementAction($sSession, $sButton, 'click')

    Sleep ($iTime)

    ; Click the ... button
    $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[2]/div/div[3]/button[2]/i")
    _WD_ElementAction($sSession, $sButton, 'click')

    ; Click the Edit button
    _WD_LinkClickByText($sSession, 'Edit')

    ; Click the Lock Until checkbox
    $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[2]/div/label")
    _WD_ElementAction($sSession, $sButton, 'click')


    ; Click the "Add Content" button
    ;$sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='add_module_item_link btn']")
    ;_WD_ElementAction($sSession, $sButton, 'click')

    ;Sleep ($iTime)

    ; Click "New Assignment" option value
    ;$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@class='module_item_select']")
    ;$sText = _WD_ElementAction($sSession, $sElement, '[ New Assignment ]')
    ;_WD_ElementAction($sSession, $sText, 'click')

    ; New Assignment Name
    ;$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//text[@name='assignment[title]']")
    ;_WD_ElementAction($sSession, $sElement, 'value', $line_split[4])

WEnd
; Close the file
FileClose($file)

;_WD_DeleteSession($sSession)
;_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": {"w3c": true }}}}'
EndFunc

Func _ChromeSetInputValueById($sSession,$Id,$Value)
 $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']")
 _WD_ElementAction($sSession,$sButton,'value', $Value)
EndFunc

 

Let me know if you need any other information. There isn't an error; I just don't know how to pull out the innerHTML to do a verification check on which Module I am manipulating on the webpage. Please if there is a resource I am not using; please point me in the direction, looking to learn. 

Thank you again, 


Thomas

Edited by ThomasBennett
Left out a " in the code; made most of the code red; hard to read. Put the code and project information inside the spoiler so my post wouldn't take up so much room. Sorry for being rude.
Link to comment
Share on other sites

@Danp2I never saw before an link-address inside with german special characters like ä, ö, ü or ß.

This is the first time. Standard to use in cases like that is to set ae, oe, ue or ss.

So, I will not be able to find a 2nd page with a link-address like that.

The original string of the address is : "#l%C3%B6hne_&amp;_geh%C3%A4lter". In clear characters = "#löhne_&_gehälter"

I am not be able to recreate this link-address with PHP for a public available website for tests.

It seems that this link-address is created by a javascript function called encodeURI.

The result of the similar function of PHP urlencode is a other string: "l%F6hne_%26_geh%E4lter".

The original menu out of the none public application is:

  <ul class="tab-titles">
   <li class="first current arrow-tab payroll-tab">
    <a href="#fehlzeiten" data-index="0">
     <span>Fehlzeiten</span>
    </a>
   </li>
   <li class=" arrow-tab payroll-tab">
    <a href="#l%C3%B6hne_&amp;_geh%C3%A4lter" data-index="1">
     <span>Löhne & Gehälter</span>
    </a>
   </li>
   <li class="last payroll-tab">
    <a href="#abrechnung" data-index="2">
     <span>Abrechnung</span>
    </a>
   </li>
  </ul>

My feeling is that this application is complete developed in javascript. 

 

Edited by Hamburgo
Link to comment
Share on other sites

Func TestPage()

DIM $Https    = "https://kmu-office.spdns.de/TDL/test/"

    _WD_Navigate($sSession, $Https)

    Sleep(5000)

   $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='#l%C3%B6hne_&amp;_geh%C3%A4lter']")
;   $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='#löhne_&_gehälter']")
;   $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='#l&#xf6;hne_&#x26;_geh&#xe4;lter']")

   ConsoleWrite(@CRLF & "Link Ref: " & $sLink & @CRLF & @CRLF)
    ConsoleWrite("Before Click" & @CRLF & @CRLF)
    _WD_ElementAction($sSession, $sLink, 'click')    ;<
    Sleep(2000)
    ConsoleWrite("After Click" & @CRLF & @CRLF)

EndFunc   ;==>TestPage

On the top you will find a snipe of my script for test.

On the bottom you will find the out on the console:

>"D:\Develop\AutoIT\SciTE\..\autoit3.exe" /ErrorStdOut "D:\Develop\AutoIT\FireFox\WebDriver\WebDriver-TestPage.au3"    
@@ Debug line    158   var: $sFirefox --> D:\WWW\Firefox\firefox.exe

@@ Debug line    20   var: $aVerQueryValue --> 66.0.2
@@ Debug line    177   var: $sGeckoDriver --> .\geckodriver\geckodriver-v0.23.0-win64\geckodriver.exe

_WDStartup: OS:    WIN_10 WIN32_NT 17134
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.17
_WDStartup: Driver:    .\geckodriver\geckodriver-v0.23.0-win64\geckodriver.exe
_WDStartup: Params:    --log trace
_WDStartup: Port:    4444
__WD_Post: URL=HTTP://127.0.0.1:4444/session; $sData={"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}
__WD_Post: StatusCode=200; ResponseText={"value":{"sessionId":"65759a56-1555-42c9-b359-0cb3f759fc7a","capabilities":{"acceptInsecureCerts":true,"browserName":"firefox","browserVersion":"66.0.2","javascriptEnabled":true,"moz:accessibilityChecks":false,"moz:geckodriverVersion":"0.23.0","moz:headless":false,"moz:processID":14004,"moz:profile":"R:\\Temp\\rust_mozprofile.OpcRSAvnBurm","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true,"nativeEvents":true,"pageLoadStrategy":"normal","platformName":"windows","platformVersion":"10.0","rotatable":false,"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"}}}
_WD_CreateSession: {"value":{"sessionId":"65759a56-1555-42c9-b359-0cb3f759fc7a","capabilities":{"acceptInsecureCerts":true,"browserName":"firefox","browserVersion":"66.0.2","javascriptEnabled":true,"moz:accessibilityChecks":false,"moz:geckodriverVersion":"0.23.0","moz:headless":false,"moz:processID":14004,"moz:profile":"R:\\Temp\\rust_mozprofile.OpcRSAvnBurm","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true,"nativeEvents":true,"pageLoadStrategy":"normal","platformName":"windows","platformVersion":"10.0","rotatable":false,"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"}}}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Running: TestPage

__WD_Post: URL=HTTP://127.0.0.1:4444/session/65759a56-1555-42c9-b359-0cb3f759fc7a/url; $sData={"url":"https://kmu-office.spdns.de/TDL/test/"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:4444/session/65759a56-1555-42c9-b359-0cb3f759fc7a/element; $sData={"using":"xpath","value":"//a[@href='#l%C3%B6hne_&amp;_geh%C3%A4lter']"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"Unable to locate element: //a[@href='#l%C3%B6hne_&amp;_geh%C3%A4lter']","stacktrace":"WebDriverError@chrome://marionette/content/error.js:179:5\nNoSuchElementError@chrome://marionette/content/error.js:389:5\nelement.find/</<@chrome://marionette/content/element.js:339:16\n"}}
_WD_FindElement: {"value":{"error":"no such element","message":"Unable to locate element: //a[@href='#l%C3%B6hne_&amp;_geh%C3%A4lter']","stacktrace":"WebDriverError@chrome://marionette/content/error.js:179:5\nNoSuchElementError@chrome://marionette/content/error.js:389:5\nelement.find/</<@chrome://marionette/content/element.js:339:16\n"}}
_WD_FindElement ==> No match: HTTP status = 404

Link Ref:

Before Click

__WD_Post: URL=HTTP://127.0.0.1:4444/session/65759a56-1555-42c9-b359-0cb3f759fc7a/element//click; $sData={"id":""}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"unknown command","message":"POST /session/65759a56-1555-42c9-b359-0cb3f759fc7a/element//click did not match a known command","stacktrace":""}}
_WD_ElementAction: {"value":{"error":"unknown command","message":"POST /session/65759a56-1555-42c9-b359-0cb3f759fc7a/el...
_WD_ElementAction ==> Webdriver Exception: {"value":{"error":"unknown command","message":"POST /session/65759a56-1555-42c9-b359-0cb3f759fc7a/element//click did not match a known command","stacktrace":""}}
After Click


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__WD_Delete: URL=HTTP://127.0.0.1:4444/session/65759a56-1555-42c9-b359-0cb3f759fc7a
__WD_Delete: StatusCode=200; ResponseText={"value":null}
_WD_DeleteSession: {"value":null}
>Exit code: 0    Time: 26.94

Link to comment
Share on other sites

@Danp2 Thanks, I will try it, but I do not believe, that will help.

I believe in your example will also works:

$sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='bücher.ch']")

because on your site the string "bücher.ch" is inside the link-address as regular characters with a single ü.

In my case/page it will be the problem that the german special character like ü will be converted to %C3%BC.

So, I am sure, that a command like the follow will also not work:

$sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href,'b%C3%BCcher.ch ')]")

I am sure that the problem comes from the url-encoding.

 

 

Edited by Hamburgo
Link to comment
Share on other sites

@Danp2 Validation:
Command did not work:

$sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href,'#l%C3%B6hne_&amp;_geh%C3%A4lter')]")

Consol-Output:

__WD_Post: URL=HTTP://127.0.0.1:4444/session/37130dae-c019-43db-a45e-1735f80784d0/element; $sData={"using":"xpath","value":"//a[contains(@href,'#l%C3%B6hne_&amp;_geh%C3%A4lter')]"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"Unable to locate element: //a[contains(@href,'#l%C3%B6hne_&amp;_geh%C3%A4lter')]","stacktrace":"WebDriverError@chrome://marionette/content/error.js:179:5\nNoSuchElementError@chrome://marionette/content/error.js:389:5\nelement.find/</<@chrome://marionette/content/element.js:339:16\n"}}
_WD_FindElement: {"value":{"error":"no such element","message":"Unable to locate element: //a[contains(@href,'#l%C3%B6hne_&amp;_geh%C3%A4lter')]","stacktrace":"WebDriverError@chrome://marionette/content/error.js:179:5\nNoSuchElementError@chrome://marionette/content/error.js:389:5\nelement.find/</<@chrome://marionette/content/element.js:339:16\n"}}
_WD_FindElement ==> No match: HTTP status = 404

 

Edited by Hamburgo
Link to comment
Share on other sites

@Danp2 The a-tag has no ID, but a property "data-index":

<a href="#l%C3%B6hne_&amp;_geh%C3%A4lter" data-index="1">

Is it possible to search with data-index='1' ?

This property with this value is unique !

Edited by Hamburgo
Link to comment
Share on other sites

@Hamburgo Both of the following work for me using https://ang.wikipedia.org/wiki/Elisabeþ_I_Engla_Cwēn

$sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href,'Maria_I_Engla_Cw%C4%93n')]")
$sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='/wiki/Maria_I_Engla_Cw%C4%93n']")

Tested with both Chrome and Firefox.

Link to comment
Share on other sites

@Danp2Ok, this information was very helpful.

Now, I know the real problem. It was not the german special characters in the link-address. Germans are think that, first.

The problem is the & = &amp;

In my test-site I am deleting the &amp; in the copy of the original-a-tag and than it works with this address, too.

And after a 2nd test I believe to know exactly the problem.

It is not the single character & = &amp;  It is the & in ALL html-entities like &OElig; etc., too.

Is there a possibility to escape the & or anything else ?

Or can I search with a part of link-adress like "#l%C3%B6hne_" ?     It is unique, too.

 

Edited by Hamburgo
Link to comment
Share on other sites

@Danp2 If it inecessary to escape the ampersand in the link, than it will not work, because I do not have access to the application for that.

To search with a partical string works. This is the solution for my current problem. 😀

Both commands are running well:

   $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href,'#l%C3%B6hne_')]")
   $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@href,'#l%C3%B6hne_') and contains(@href,'_geh%C3%A4lter')]")

Many thanks for your support.

Link to comment
Share on other sites

The truth is a other one:
Html-entities are direct converted by the driver to the real single character, but not the url-codes für special characters, like the german once.

1.    $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='#l%C3%B6hne_&amp;_geh%C3%A4lter']")
2.   $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='#löhne_&_gehälter']")

3.   $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='#l%C3%B6hne_&_geh%C3%A4lter']")

1.  Do not work.    (Source-code of the original-page)

2.  Do not work.   (converted result of the browser, if hold the mouse over the original-link)

3.  This works.

 

Link to comment
Share on other sites

2 hours ago, Hamburgo said:

Html-entities are direct converted by the driver to the real single character, but not the url-codes für special characters

OIC. So just replace the HTML representation of the ampersand with the real thing and all is well, correct? Glad you were able to figure that out.

P.S. When I mentioned escaping the ampersand, I was suggesting to do that in your code, not in the source website.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...