Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

9 hours ago, Danp2 said:

I've been doing some testing on this and want to be sure that we make the correct change. Can someone explain why I get the same result for the two split string values?

#include <MsgBoxConstants.au3>

Local $sSplitValue, $sSplitValue2
Local $sOption = 'ąśł'

MsgBox($MB_SYSTEMMODAL, "Original", $sOption)

$sSplitValue = "[" & StringTrimRight(StringRegExpReplace($sOption, '.', '"$0",'), 1) & "]"
$sSplitValue2 = "[" & StringTrimRight(StringRegExpReplace($sOption, '\\u[[:alnum:]]{4}|.', '"$0",'), 1) & "]"
MsgBox($MB_SYSTEMMODAL, "Split", $sSplitValue & @crlf & $sSplitValue2)

 

Because you didn't change characters to codes:

Local $sOption = 'ąśł'

should be

Local $sOption = '\u0105\u015B\u0142'

 

6 hours ago, Danp2 said:

@grzesiek

I believe that I have found the correct way to address the issue. Please change the following line in __WD_Post from

$sResponseText = _WinHttpSimpleRequest($hConnect, "POST", $aURL[6], Default, $sData)

to

$sResponseText = _WinHttpSimpleRequest($hConnect, "POST", $aURL[6], Default, StringToBinary($sData, 4))

and then retest with the Polish text.

It almost works but when I enter 'ćłą' I get some chinese character instead.

Share this post


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

Local $sOption = '\u0105\u015B\u0142'

Like I said before, this isn't my area of expertise. :D I take another look at this.

1 hour ago, grzesiek said:

It almost works but when I enter 'ćłą' I get some chinese character instead.

That's odd. Can you post some code to demonstrate what you are seeing?

What you do get with the following?

#include <wd_core.au3>

Local Enum $eFireFox = 0, _
            $eChrome

Local Const $_TestType = $eChrome
Local $sDesiredCapabilities
Local $sText
Local $sSession

$_WD_DEBUG = $_WD_DEBUG_Info

Switch $_TestType
    Case $eFireFox
        SetupGecko()

    Case $eChrome
        SetupChrome()

EndSwitch

_WD_Startup()

$sText = 'ćłą'

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://google.com")
$iElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='q']")
_WD_ElementAction($sSession, $iElement , 'value', $sText)

    $sValue = _WD_ElementAction($sSession, $iElement, 'property', 'value')

MsgBox(0, 'test', $sValue)

_WD_Window($sSession,'close')
_WD_DeleteSession($sSession)
_WD_Shutdown()


Func SetupGecko()
_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
EndFunc

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 }}}}'
EndFunc

 

Share this post


Link to post
Share on other sites

I used the default 'Code Page Property' encoding. But strange to me is that it works with 'Code Page Property' if I change:

_WD_ElementAction($sSession, $iElement , 'value', $sText)

to

_WD_ElementAction($sSession, $iElement , 'value', $sText) ;ąśą

so If I add some random polish letters after calling the function.

Edited by grzesiek

Share this post


Link to post
Share on other sites

there is anyway to run "pageLoadStrategy":"eager"  in chrome ?!  only none and normal work for me... also there is anyway to check if the page is loading or no ?!

Share this post


Link to post
Share on other sites
5 minutes ago, omarjr16 said:

there is anyway to run "pageLoadStrategy":"eager"  in chrome ?!  only none and normal work for me

Not until the functionality is implemented.

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1902&q=pageLoadStrategy&colspec=ID Status Pri Owner Summary

7 minutes ago, omarjr16 said:

also there is anyway to check if the page is loading or no ?!

I've considered creating the function_WD_LoadWait. I actually wrote something a while back, but haven't really tested it.

Share this post


Link to post
Share on other sites

I've searched this topic, the other topic related to WD, and the functions within the UDF and for the life of me i cannot find a way to open firefox in privatebrowsing, can it be done and if so how?

Share this post


Link to post
Share on other sites

@Shaden Google is your friend when you can't find a prior example in the forum. ^_^

Read this for details on using "moz:firefoxOptions" as part of the capabilities string. Here's an example desired capabilities string --

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"moz:firefoxOptions": {"args": ["--private"]}}}}'

 

Share this post


Link to post
Share on other sites

@omarjr16 Try this and let me know how it works for you --

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities

Local Enum $eFireFox = 0, _
            $eChrome

Local Const $_TestType = $eFireFox

Switch $_TestType
    Case $eFireFox
        SetupGecko()

    Case $eChrome
        SetupChrome()

EndSwitch

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "http://www.google.com")
_WD_LoadWait($sSession, 500, 2000)
consolewrite('@error=' & @error & @CRLF)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='q']")

_WD_Navigate($sSession, "http://www.yahoo.com")
_WD_LoadWait($sSession, -1, -1, $sElement)
consolewrite('@error=' & @error & @CRLF)

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_LoadWait
; Description ...: Wait for a browser page load to complete before returning
; Syntax ........: _WD_LoadWait($sSession[, $iDelay = 0[, $iTimeout = -1[, $sElement = '']]])
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $iDelay              - [optional] Milliseconds to wait before checking status
;                  $iTimeout            - [optional] Period of time to wait before exiting function
;                  $sElement            - [optional] Element ID to confirm DOM invalidation
; Return values .: Success      - 1
;                  Failure      - 0 and sets the @error flag to non-zero
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_LoadWait($sSession, $iDelay = 0, $iTimeout = -1, $sElement = '')
    Local Const $sFuncName = "_WD_LoadWait"
    Local $iErr, $sResponse, $sJSON, $sReadyState

    If $iTimeout = -1 Then $iTimeout = $_WD_DefaultTimeout

    If $iDelay Then Sleep($iDelay)

    Local $hLoadWaitTimer = TimerInit()

    While True
        If $sElement <> '' Then
            _WD_ElementAction($sSession, $sElement, 'name')

            If $_WD_HTTPRESULT = $HTTP_STATUS_NOT_FOUND Then $sElement = ''
        Else
            $sResponse = _WD_ExecuteScript($sSession, 'return document.readyState', '')
            $iErr = @error

            If $iErr Then
                ExitLoop
            EndIf

            $sJSON = Json_Decode($sResponse)
            $sReadyState = Json_Get($sJSON, "[value]")

            If $sReadyState = 'complete' Then ExitLoop
        EndIf

        If (TimerDiff($hLoadWaitTimer) > $iTimeout) Then
            $iErr = $_WD_ERROR_Timeout
            ExitLoop
        EndIf

        Sleep(100)
    WEnd

    If $iErr Then
        Return SetError(__WD_Error($sFuncName, $iErr, ""), 0, 0)
    EndIf

    Return SetError($_WD_ERROR_Success, 0, 1)
EndFunc


Func SetupGecko()
_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true, "pageLoadStrategy":"none"}}'
EndFunc

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}, "pageLoadStrategy":"none"}}}'
EndFunc

 

Share this post


Link to post
Share on other sites

One of our environments got a bunch of updates over the last weekend, and since then I have not been able to get chromedriver.exe to work in that env.

Chrome opens, but sits at an empty data;, page.

I have been using the little demo script I posted in the UDF thread to try and troubleshoot, but it never really gets anywhere..

What the chrome.log shows

Quote

[1537282533.137][INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=0 --start-maximized --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\...\scoped_dir32208_17987" data:,
[1537282533.718][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1537282543.201][SEVERE]: Unable to receive message from renderer
[1537282543.240][INFO]: [62635baf2551f036527e7ff4b5fb4b8e] RESPONSE InitSession ERROR session not created
from disconnected: Unable to receive message from renderer
  (Session info: chrome=69.0.3497.92)

 

Now for the extra strange part.  If I switch over to use headless via:  "args":["headless", "disable-gpu", "disable-infobars"]  the script works fine.

All I can find using google searches says to use the latest chromedriver.exe which I already am, or to submit a bug to chromium.


hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites

I'm using the v2.42.  I was using 2.40 but part of the updates this last weekend was updating chrome to 69 which forced me to use the newer chromedriver.

I keep thinking there must be some new security policy or restriction put into place but our Infrastructure & Security team keep telling me there weren't any changes like that.

 

edit:  Just tried the 2.41 since it will also support 69 and it's having the same problem.

Edited by BigDaddyO

hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites

am I missing something simple?

I'm trying to select an item from a drop down but I don't see any method to select an item from a list.  I tried to send a click, but that didn't work.

$eHIPPAtype = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[contains(@id,'callerTypeOptions') and not(contains(@id, 'callerTypeOptions1')) and contains(@class, 'callerTypeOptions')]")
$eHIPPAtypeMbr = _WD_FindElement($sSession, "//option[contains(@value, 'Member')][1]", $eHIPPAtype, False)  ;Starting at the Select list, find the first object that contains Member as thats what I want


_WD_ElementAction($sSession, $eHIPPAtypeMbr, "click")   ;Click doesn't work, how do I select?

 


hmm... I guess I have to have a signature...

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