Danp2 Posted May 5, 2022 Author Posted May 5, 2022 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? Latest Webdriver UDF Release Webdriver Wiki FAQs
SkysLastChance Posted May 5, 2022 Posted May 5, 2022 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
Danp2 Posted May 5, 2022 Author Posted May 5, 2022 @SkysLastChanceMost likely the first script is crashing because the second script closes existing instances of the webdriver. You can control this with _WD_Option and DRIVERDETECT / DRIVERCLOSE options. SkysLastChance 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
SkysLastChance Posted May 5, 2022 Posted May 5, 2022 This seemed to do the trick. Thank you! _WD_Option('DriverClose', False) _WD_Option('DriverDetect', False) You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
CYCho Posted May 5, 2022 Posted May 5, 2022 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. Danp2 1 zPlayer - A Small Audio and Video Player
SkysLastChance Posted May 6, 2022 Posted May 6, 2022 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
Danp2 Posted May 7, 2022 Author Posted May 7, 2022 _WD_Shutdown shouldn't be called if you want the webdriver console to stay running on script exit. Latest Webdriver UDF Release Webdriver Wiki FAQs
seadoggie01 Posted May 9, 2022 Posted May 9, 2022 @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! SkysLastChance 1 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
SkysLastChance Posted May 9, 2022 Posted May 9, 2022 (edited) @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 May 9, 2022 by SkysLastChance You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
seadoggie01 Posted May 10, 2022 Posted May 10, 2022 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 SkysLastChance 1 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
SkysLastChance Posted May 10, 2022 Posted May 10, 2022 Love this! Thank you. I don't know why I can't think of stuff like this. 😕 This should be in the wd_helper. You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
Keras Posted May 11, 2022 Posted May 11, 2022 (edited) 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 May 11, 2022 by Keras mLipok 1
Jemboy Posted May 13, 2022 Posted May 13, 2022 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 😀
Danp2 Posted May 13, 2022 Author Posted May 13, 2022 I would suggest using _WD_ElementActionEx -- $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='remember']") _WD_ElementActionEx($sSession, $sElement, 'check') Latest Webdriver UDF Release Webdriver Wiki FAQs
Jemboy Posted May 13, 2022 Posted May 13, 2022 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.
Danp2 Posted May 13, 2022 Author Posted May 13, 2022 @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. Latest Webdriver UDF Release Webdriver Wiki FAQs
Jemboy Posted May 13, 2022 Posted May 13, 2022 (edited) @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 May 13, 2022 by Jemboy
Danp2 Posted May 13, 2022 Author Posted May 13, 2022 @Jemboy Use the one that best suits the task at hand -- _WD_ElementAction implements standard webdriver actions related to elements _WD_ElementActionEx implements additional "advanced" actions that either involve executing a Javascript command or performing a set of actions with _WD_Action Jemboy 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Jemboy Posted May 14, 2022 Posted May 14, 2022 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 😁)
Danp2 Posted May 14, 2022 Author Posted May 14, 2022 That's not really a webdriver-related question, so you may want to start a separate thread. P.S. There are ways to start the console so that it isn't visible. Jemboy 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Recommended Posts