Jump to content

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

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

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

 

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

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

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...