Jump to content

WebDriver UDF - Help & Support (III)


Danp2
 Share

Recommended Posts

37 minutes ago, CYCho said:

_WD_SetElementValue using an $iStyle of $_WD_OPTION_Advanced works with $sValue containing @CRLF, but it can't accomodate double quotation. The following code works fine.

Yes, that makes sense because internally $sValue is wrapped in double quotes before being passed to _WD_ExecuteScript.

I wonder if it would also work like this?

$sValue = StringReplace($sValue, '"', """")

If it works, then this might be a better solution since $sValue could also contain single quotes.

P.S. Can you elaborate on your situation? What type of element are you updating?  Why are you setting the value to HTML?

Link to comment
Share on other sites

I am having a problem when using RDS. 

If I have 2 people on the same server and they are both running my script it crashes one of them. 

I thought it might be the port. However, I seems to run fine if they are on the same port. It looks like the problem is the chromedriver.exe

If I name them diffrently they both seem to run fine. 

For instance if I have chromedriver1.exe on one and chromedirver.exe on the other they both work.

However, don't want to make two diffrent scripts. What would be the best way to solve this problem? Any ideas? 

Local $iAltPort = 9516 
_WD_Option('Driver', 'chromedriver.exe') 
_WD_Option('DriverParams', '--verbose --port=' & $iAltPort & ' --log-path="' & @ScriptDir & '\chrome.log"')
_WD_Option('Port', $iAltPort)

 

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

6 hours ago, Danp2 said:

$sValue = StringReplace($sValue, '"', """")

This doesn't work.

6 hours ago, Danp2 said:

What type of element are you updating?  Why are you setting the value to HTML?

The element I have to update is a text area of an embedded editor for a blog post which has an HTML writing mode.

Link to comment
Share on other sites

Regarding my last question on here. 

Should I be shutting down the session diffrently? I have a feeling this caused my other users script to crash again. One person finished with the script and then boom the others stopped working again. 

My guess is this is the cause _WD_Shutdown()

_WD_DeleteSession($sSession)
_WD_Shutdown()

Any ideas?

 

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

@SkysLastChance I have a similar use case where I consistently have multiple scripts that use the WebDriver open at once. Because I don't want to use many drivers, I use a personal include (WD_Ex.au3) where I keep some helper functions.

  • _WDEx_Startup creates a new session using an existing driver if possible and records the PID and session handle to a config file
  • _WDEx_CloseSession closes a session and removes the session handle from the config
  • _WDEx_Shutdown attempts to close the driver, but first checks to see if any sessions are still alive. It also uses _WD_Action($sSession, "url") to determine if "alive" scripts are actually alive or if they were closed but not removed from the config (because I forget to use my functions sometimes :))

An example config file:

[PIDs]
123=True
456=Value here doesn't matter
[123]
<session handle>=True
<session2 handle>=Again, value doesn't matter here
...

By doing this, I've maintained some semblance of order while running multiple sessions under a single driver. I hope this is helpful!

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

@seadoggie01 Very Cleaver. I am going to give this a try. I knew there would come a time when I would need a config file.  Thank you.

 

If you wanted to share your UDF I woulden't be mad.... HAHA

Edited by SkysLastChance

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

Only parts of it would be useful and I don't plan to use it if I were to clean it up. There's a lot of customization that I've put into it, like setting up my webdriver exactly the way I want it. It wouldn't be useful to me without it or useful to you with it :)

I will give you my most used function, though. Despite its simplicity, I use it ALL the time.

Spoiler
; Literally, find an element and perform an action on it. Sounds silly, but saves sooo much typing :D
Func _WDEx_ElementFindAction($sSession, $sStrategy, $sSelector, $sStartElement, $sCommand, $sOption = "")

    Local $sElement = _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement)
    If ErrMsg(_WD_FindElement) Then Return SetError(100 + @error, @extended, False)

    Local $vRet = _WD_ElementAction($sSession, $sElement, $sCommand, $sOption)
    If ErrMsg(_WD_ElementAction) Then Return SetError(200 + @error, @extended, False)

    Return $vRet

EndFunc

 

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Hello, can you explain how WebDriver works when i do an action on my current Window that open "a child window" that WebDriver will add to the list of the window he handles ?

I got some problems with IEDriver, sometimes (randomly) when i do an action that is opening a new window, my program freeze a little bit before the window is created and then, my driver never get the handle of the new window (even 5 minute later when i'm 100% sure it's full loaded). When it happens, i can see in the log that my '_wd_attach' fails because he doesn't handle any window anymore (the first window is closed to open the new one):

__WD_Get: URL=HTTP://127.0.0.1:5555/session/aeca4638-12c0-4220-a95d-bf63d8c54cd8/window/handles
__WD_Get ==> Success (0) HTTP status = 200 : ResponseText={
    "value" : []
}

All i can do after that is recreating a new session.

 

In the example bellow, the website i open, automatically close the first window and open  a new one to the homepage. When it's done, i try to attach the new one.

I did a loop to repeat those action and i got the problem i detailed above almost twice out of the 19 try

Example :

For $i = 0 To 19
    _Setup_IEDriver()
    $sWDSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_LoadWait($sWDSession)
    _WD_Navigate($sWDSession, $sUrl)
    _WD_LoadWait($sWDSession)
    For $j = 1 To 100
        _WD_Attach($sWDSession, $sUrl & "homepage.do", 'URL')
        If Not (@error) Then ExitLoop
        Sleep(300)
    Next
    If $j = 101 Then
        ConsoleWrite("! STOP ERROR ATTACH HOMEPAGE" & @CRLF)
    EndIf
    Sleep(500)
    _WD_DeleteSession($sWDSession)
    _WD_Shutdown()
    Sleep(2000)
Next

Func _Setup_EDGEDriver()
    _WD_Option('Driver', @ScriptDir & '\include\' & (@Compiled ? '' : 'Exe_externe\') & 'msedgedriver.exe')
    _WD_Option('Port', 9515)
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args": []}}}}'
    _WD_Startup()
EndFunc   ;==>_Setup_EDGEDriver

Edit : It looks like a known bug : https://github.com/SeleniumHQ/selenium/issues/8868

Edited by Keras
Link to comment
Share on other sites

HI, I have been automating the following: https://login.tecalliance.net/
My script already logs into the website, however somehow I cannot succceed the tick the checkbox.

I have used the following code, but neither checks the checkbox.

;Try to check checkbox by name
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='remember']")
MsgBox ($MB_topmost,$sTitle,"$sElement: " & $sElement)
_WD_ElementAction($sSession, $sElement, 'click')


;Try to check checkbox by ID
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='input47']")
MsgBox ($MB_topmost,$sTitle,"$sElement: " & $sElement)
_WD_ElementAction($sSession, $sElement, 'click')

Both do not check the checkbox.
Could someone give some tips how to get this checkbox checked 😀

image.png.d713dd9b1df6fb976d9e659cb7d0b133.png 

Link to comment
Share on other sites

1 hour ago, Danp2 said:

I would suggest using _WD_ElementActionEx --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='remember']")
_WD_ElementActionEx($sSession, $sElement, 'check')

 

Just tested this. $sElement gets a value, but using _WD_ElementActionEx with 'check', 'click' did not work.

Link to comment
Share on other sites

@JemboyI just tested the code I posted, and it worked correctly for me with both Chrome and FireFox. Unsure why it isn't working for you. Perhaps you aren't using the latest copy of the UDF?

Note that my example uses "check", not "click". You mentioned both of them in your last post but you didn't show your code, so we have no way of knowing why version didn't work as expected.

Link to comment
Share on other sites

@Danp2 YES!! Thank you very much!
After upgrading the Webdriver UDFto  v0.90 your code snippet (with 'check') works as intended,👍😀

Till now, I only used _WD_ElementAction with my scripts. Is there some explanation or rule of tumb when to use _WD_ElementActionEx instead of _WD_ElementAction ?

Edited by Jemboy
Link to comment
Share on other sites

I have 3 websites starting automated and login, using Autoit and the webdriver (Chrome).
I noticed sometimes it is hard to tell which program is which because they all have a Chrome icon pn the taskbar while running
and my users also have multiple instances of Chrome opened.

Is there a way to assign other icons to the Chromedriver instances or show the fav.ico of the site as an icon for these Chrome web driver instances ?
(I have done several searches, but I only get answers were people wan't to change tie Chrome shortcut icons 😁)
 

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 07/29/2022
  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...