Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

#include <wd_core.au3>

HotKeySet("{F4}", "iWeirdo")

Local $iWeirdo = 1

$_WD_Capabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true,"args":["disable-infobars"] }}}}'
$_WD_DEBUG = False
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('DriverParams', '--verbose --log-path=' & @ScriptDir & '\secretlog-shhhhhh.log')
_WD_Option('Port', 9515)

_WD_Startup()
$sSession = _WD_CreateSession($_WD_Capabilities)

do
   _WD_Navigate($sSession, "https://google.com")
   $iElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@class='gsfi']")
   _WD_ElementAction($sSession, $iElement , 'value', "hot 6 years old girls")
   $ibutton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@value='Google Search']")
   _WD_ElementAction($sSession, $iElement , 'click')
   consolewrite("you are added to 'fbi weirdo registry' shame on u danp2")
until $iWeirdo = 0

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


Func iWeirdo()
   $iWeirdo = 0
Endfunc

this simple script  need +0.2mb of ram every 3s (no stop) 

running this awkward function in loop will need 2mb of ram every 1s (depend on ur cpu)

no problems in my script B) fix ur broken udf :shifty:

Func _WD_ClickWaitElement($Session, $Strategy, $Selector, $Timeout, $poi)
   $hWaitTimer = TimerInit()
   While 1
      $sElement = _WD_FindElement($Session, $Strategy, $Selector)
      If not @error Then
         if $poi = 1 then _WD_ElementAction($Session,$sElement,'click')
         $p = 1
         ExitLoop
      EndIf
      If TimerDiff($hWaitTimer) > $Timeout Then
         $p = 0
         Exitloop
      EndIf
   WEnd
   Return $p
EndFunc

 

Edited by omarjr16

Share this post


Link to post
Share on other sites

Um.... nope. Don't think I'll be running that script unmodified. :blink:

P.S. What's with the function you posted? It doesn't appear relevant to the discussion (it isn't being called by the earlier script)

P.P.S. How are you measuring the ram usage? And is it growing in the browser, the web driver, or the actual script?

Share this post


Link to post
Share on other sites

using windows task manager + ram growing in the script ...also dont care about the function its an other exemple who take  alot more ram then the first script ;) just run the first script and u will see that ram usage will increase by time its small maybe in that one but very big in some other scripts 

Edited by omarjr16

Share this post


Link to post
Share on other sites

Do you know how can I in chromedriver use _WD_ElementAction to set the value of an element to value which contains polish letters eg. ąśł?

Share this post


Link to post
Share on other sites

 i want the script to skip"findelement" in case that the page still loading but _WD_FindElement function wait the page until it complete loading then try to find the element ... can _WD_Timeouts or pageLoadStrategy  solve this problem? _WD_Timeouts dont work at the moment in chromedriver and idk how to change pageloadstrategy in chrome :c

_WD_ExecuteScript($sSession, "location.reload();") ;reload the page 
_WD_Alert($sSession, 'accept') ;skip alert
sleep(2000)
_WD_FindElement(...) ; Find An Element
 .
 .
 .

Also how to perform keyboard +pointer actions?

https://w3c.github.io/webdriver/#perform-actions

Edited by omarjr16

Share this post


Link to post
Share on other sites
3 hours ago, grzesiek said:

Do you know how can I in chromedriver use _WD_ElementAction to set the value of an element to value which contains polish letters eg. ąśł?

What have you tried? Show us your code and explain exactly what isn't working as expected.

Finally, tell us what steps you have tried to troubleshoot the issue, ie --

  • Have you tried with a different browser?
  • Does your code work with non-unicode text?

Share this post


Link to post
Share on other sites

thank you again c: but ididnt guess yet how to solve my first problem 

5 hours ago, omarjr16 said:

 i want the script to skip"findelement" in case that the page still loading but _WD_FindElement function wait the page until it complete loading then try to find the element

 i dont know where to put "pageloadstrategy":"none" in what part ??

'{"capabilities": {"alwaysMatch":{"chromeOptions":{"w3c": true,"args":["disable-infobars","user-data-dir=/Custom/Profile' & $i & '"]}}}}'

 

Edited by omarjr16

Share this post


Link to post
Share on other sites
7 hours ago, Danp2 said:

What have you tried? Show us your code and explain exactly what isn't working as expected.

Finally, tell us what steps you have tried to troubleshoot the issue, ie --

  • Have you tried with a different browser?
  • Does your code work with non-unicode text?

When I add this to the demo script I receive an error 'missing command parameters' and the value is not typed:

_WD_ElementAction($sSession, $sElement, 'value', "ąśł")

When I don't use polish letters the value is typed.

In firefox I also can't type polish letters.

To set the value I have to use _WD_ExecuteScript but first I have to change polish characters to codes and prefix them with '\u', for example to enter the letter 'ą':

_WD_ExecuteScript($sSession, "document.getElementById('lst-ib').value='\u0105'")

But when I want to set the value of a file input element to upload a file I can't set the value through _WD_ExecuteScript so I have to use a path without polish letters to upload a file.

Edited by grzesiek

Share this post


Link to post
Share on other sites

I found out how to do this. You have to change in wd_core:

Local $sSplitValue = "[" & StringTrimRight(StringRegExpReplace($sOption, '.', '"$0",'), 1) & "]"

to

Local $sSplitValue = "[" & StringTrimRight(StringRegExpReplace($sOption, '\\u[[:alnum:]]{4}|.', '"$0",'), 1) & "]"

so the character codes wouldn't be splitted.

Also maybe would be better to change non ASCII characters to codes internally in the UDF.

Share this post


Link to post
Share on other sites

Also when I want to type the '\' character it needs to be doubled so I need to enter '\\'. So you have to change to:

Local $sSplitValue = "[" & StringTrimRight(StringRegExpReplace($sOption, '\\\\|\\u[[:alnum:]]{4}|.', '"$0",'), 1) & "]"

Share this post


Link to post
Share on other sites

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)

 

Share this post


Link to post
Share on other sites

AFAICS, the issue isn't with the StringRegExpReplace in _WD_ElementAction. Rather, it is with the _WinHttpSendRequest call in __WD_Post.

_WinHttpSendRequest creates a byte array structure and stores the string into this array. It's at this point that the unicode characters are getting "lost".

Share this post


Link to post
Share on other sites

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

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