duke241 Posted February 27, 2023 Share Posted February 27, 2023 And how I can add new attribute to an element? Thanks Link to comment Share on other sites More sharing options...
Danp2 Posted February 27, 2023 Author Share Posted February 27, 2023 FWIW, the ability to remove an element was recently added to _WD_ElementActionEx by @SOLVE-SMART, and this functionality will be in the next release. SOLVE-SMART 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted February 27, 2023 Author Share Posted February 27, 2023 @duke241See prior answer from @seadoggie01. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
duke241 Posted February 27, 2023 Share Posted February 27, 2023 1 minute ago, Danp2 said: @duke241See prior answer from @seadoggie01. Thank you two Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted February 27, 2023 Share Posted February 27, 2023 16 minutes ago, Danp2 said: [...] was recently added to _WD_ElementActionEx by @SOLVE-SMART You are a very polite person @Danp2 😀 . Thanks for the credits - not necessary, but thanks 🤝 . Best regards Sven Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
fmendi Posted February 27, 2023 Share Posted February 27, 2023 I hesitate to even to show my face in this topic since I am far from a programmer, and I basically learn by piecing together code from examples. However, I really would like to be able to automate Chrome, at least to a basic degree. I've been lurking for a while and have learned that the WebDriver udf is far above my pay grade of understanding, yet I keep coming back to it. OK. here is what I would like to do. Open Chrome with my own profile, go to any webpage and be able to extract the page's text to use in Regex....over and over again. The script uses a loop and a middle-click trigger to do so. Hopefully, I am not too far out of my league with this. Thanks in advance. AutoitQ.au3 Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted February 27, 2023 Share Posted February 27, 2023 (edited) Don't hesitate @fmendi 😀 , the most forum members are very helpful and polite. Besides that your script is indeed incomplete, but not too bad. Can you please explain a bit further what do you mean by "Open Chrome with my own profile"? I saw your capabilities string with the user-data arg, but are you sure you want to do this? Why? You described: 27 minutes ago, fmendi said: [...] go to any webpage and be able to extract the page's text [...] So a clean/default chromedriver instance could do the same thing. No need for your profile. Best regards Sven Edited February 27, 2023 by SOLVE-SMART Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
fmendi Posted February 27, 2023 Share Posted February 27, 2023 Thanks for the quick reply, Sven. The reason I need to run Chrome under my profile is that the script will eventually be pretty long with auto log- ins to several websites as well as the use of a couple of chrome extensions. Below is where $sText comes up nul. Thanks.... Func MClick() $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body") $sText = _WD_ElementAction($sSession, $sElement, "text") MsgBox(1, "",$sText) ; *******ERROR*********** EndFunc expandcollapse popupOpt("GUIOnEventMode", 1) Opt("WinTitleMatchMode", 2) Opt("TrayIconDebug", 1) #include "wd_core.au3" #include <GUIConstantsEx.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <Date.au3> #Include <_SendEx.au3> ;prevent keys from sticking dim $dll = DllOpen("user32.dll") _Singleton(@Scriptname) ;==================================================== Local $sDesiredCapabilities, $sSession $_WD_DEBUG = $_WD_Debug_Info $_WD_ERROR_MSGBOX = False $_WD_DEBUG = $_WD_DEBUG_None ;Hides console at startup SetupChrome() If Not ProcessExists("chromedriver.exe") Then _WD_Startup() EndIf If @error <> $_WD_ERROR_Success Then Exit EndIf ; sets up chrome with Google and Yahoo tabs open WinActivate("Chrome") WinWaitActive("Chrome", "", 10) _SendEx("+^m") ;opens my profile in a new Chrome Window Sleep(200) _SendEx("{enter}") _SendEx("^t") ;opens Yahoo tab ClipPut("https://yahoo.com") _SendEx("^v{enter}^1") WinMove("Chrome", "", @DesktopWidth/15, 0, @DesktopWidth - 125, @DesktopHeight -35); moves chrome a touch away from right side of screen Sleep(3000) WinClose("New Tab") ;Closes first chrome window ;==========================================START LOOP======================================== While 1 $_i1 = MouseGetPos() If _IsPressed('04', $dll) Then Call ("MClick"); Middle Click If Not WinExists("Chrome") Then exit Sleep(10) WEnd ;==========================================END LOOP========================================== ;==========================================FUNCTIONS====================================== Func MClick() $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body") $sText = _WD_ElementAction($sSession, $sElement, "text") MsgBox(1, "",$sText) ; *******ERROR*********** EndFunc Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\DOCMJ\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Default"]}}}}' $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Option('DriverParams', '--marionette-port 2828') EndFunc Link to comment Share on other sites More sharing options...
seadoggie01 Posted February 27, 2023 Share Posted February 27, 2023 I don't recommend sending data to the UDF with sendkeys. I also wouldn't recommend storing passwords in script files for any period of time, though that's a concern for later in the scripting process. When you want to fix that, try taking a look at KeePass. As for how to use this UDF without copy/paste and sendkeys, I'd suggest getting really familiar these functions: _WD_Navigate - Go to a URL _WD_FindElement - Find a thing on a page, could be a username input in your case _WD_ElementAction - Do a thing with that element you found, like setting the value to your username or clicking a button When you get those figured out, you'll be able to do most of the basic stuff. Your script is possibly breaking for a few reasons. I'm guessing though that you're not always creating the session since Chrome is already open. I suggest always creating a new instance and closing the old one when your script quits. Managing sessions is a pain IMHO 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 Link to comment Share on other sites More sharing options...
fmendi Posted February 27, 2023 Share Posted February 27, 2023 Thanks for the suggestions, seadoggie! Quote Your script is possibly breaking for a few reasons. I'm guessing though that you're not always creating the session since Chrome is already open. I suggest always creating a new instance and closing the old one when your script quits. Managing sessions is a pain IMHO My plan was to start fresh by opening a chrome session under the umbrella of WebDriver and keeping it alive with the WEnd loop. I thought that the problem might be because of closing the original Chrome window (WinClose("New Tab"), however, commenting that part out does not fix the problem. Link to comment Share on other sites More sharing options...
CodeWriter Posted March 2, 2023 Share Posted March 2, 2023 @Danp2FYI, I have tried to use the method listed in WebDriver Wiki to utilize an existing profile in MS Edge without any success, namely: $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args": ["user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Microsoft\\Edge\\User Data\\", "profile-directory=Default"]}}}}' This may be helpful for other users who have the same difficulty but after lots of experimentation, I found that the following capabilities string does work to launch MS Edge with an existing profile if you remove the "profile-directory" args and listing the chosen profile, e.g. "Profile 1" in this case: $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"excludeSwitches": [ "enable-automation"], "args": ["user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Microsoft\\Edge\\User Data\\Profile 1"]}}}}' And the corresponding method using @mLipok wd_capabilities.au3 _WD_CapabilitiesStartup() _WD_CapabilitiesAdd('alwaysMatch', 'msedge') _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation') _WD_CapabilitiesAdd('args', 'user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Microsoft\\Edge\\User Data\\Profile 1') $sDesiredCapabilities = _WD_CapabilitiesGet() If you agree, perhaps the Wiki suggested example could be amended. Link to comment Share on other sites More sharing options...
Danp2 Posted March 2, 2023 Author Share Posted March 2, 2023 @CodeWriterThe existing method works for others, including me. I think the safest option is to add a comment explaining to replace "Default" as needed to the value shown in edge://version. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CodeWriter Posted March 2, 2023 Share Posted March 2, 2023 @Danp2OK, but please include an explanation that dividing the profile path into 2 args: "user-data-dir=' and 'profile-directory=' will fail for some like me even when you replace "Default" with a specified profile "Profile 1". Link to comment Share on other sites More sharing options...
Danp2 Posted March 2, 2023 Author Share Posted March 2, 2023 @CodeWriterThanks for the clarification as I didn't detect that from your earlier post. To clarify, you are saying that this works -- $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args": ["user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Microsoft\\Edge\\User Data\\Profile 1"]}}}}' but this doesn't work? $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args": ["user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Microsoft\\Edge\\User Data\\", "profile-directory=Profile 1"]}}}}' If that's accurate, then I wonder if the space in the profile name is causing issues. 🤔 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CodeWriter Posted March 2, 2023 Share Posted March 2, 2023 (edited) Yes, the former works (but not with "Default"), and the latter does NOT work with any profile name ("Default" or otherwise). Not sure if the space is a factor because it is still present in the style that works. Edited March 2, 2023 by CodeWriter Link to comment Share on other sites More sharing options...
HJL Posted March 2, 2023 Share Posted March 2, 2023 Hi Dan, could you be so kind and declare $sDriverCurrent and $sDriverLatest from _WD_UpdateDriver() as global in the next release? I need these vars in my program. Thanks a lot Hans Link to comment Share on other sites More sharing options...
Danp2 Posted March 2, 2023 Author Share Posted March 2, 2023 @HJLThese are local variables to _WD_UpdateDriver, and they should remain local IMO. However, there are functions that allow you to retrieve these values yourself. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted March 2, 2023 Share Posted March 2, 2023 (edited) Hi @HJL, I think this isn't necessary. You can get the WebDriver version like in wd_helper.au3 by: Global $sCurrentWebDriverVersion = _WD_GetWebDriverVersion($sInstallDir, $sDriverEXE) Also for the latest WebDriver info, you can use this: Global $sLatestWebDriverInfo = __WD_GetLatestWebdriverInfo($aBrowser, $sBrowserVersion, $bFlag64)[1] Best regards Sven Edited March 2, 2023 by SOLVE-SMART Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
HJL Posted March 2, 2023 Share Posted March 2, 2023 (edited) 7 minutes ago, Danp2 said: @HJLThese are local variables to _WD_UpdateDriver, and they should remain local IMO. However, there are functions that allow you to retrieve these values yourself. If I would know how to do it I wouldn't ask 😉 But the solution is one thread above 😉 Edited March 2, 2023 by HJL Link to comment Share on other sites More sharing options...
Danp2 Posted March 2, 2023 Author Share Posted March 2, 2023 @HJLThe coding has already been done in _WD_UpdateDriver. You simply need to extract the relevant parts and use them in your own script. You can copy and paste, right? 😏 SOLVE-SMART 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Recommended Posts