CaptainBeardsEyesBeard Posted September 29, 2023 Posted September 29, 2023 Hi i've tried accessing the following html via numerous methods <h2 class="MhrCore-homeCardTitle" id="MhrCore-homeCardTitle--ooo">Nobody is out of the office today</h2> I tried via xpath and id using innerText, text and value $eXpath = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@id="MhrCore-homeCardTitle--ooo"]') $xInner = _WD_ElementAction($sSession, $eXpath, 'property', 'innerText') $xValue = _WD_ElementAction($sSession, $eXpath, 'property', 'value') $XText = _WD_ElementAction($sSession, $eXpath, 'property', 'text') WriteToConsoleAndLog("x inner =: " & $xInner) WriteToConsoleAndLog("x value =: " & $xValue) WriteToConsoleAndLog("x text =: " & $XText) $id = _WD_GetElementById($sSession, 'MhrCore-homeCardTitle--ooo') $ClipData = _WD_ElementAction($sSession, $id, 'property', 'innerText') $ClipData2 = _WD_ElementAction($sSession, $id, 'property', 'value') $ClipData3 = _WD_ElementAction($sSession, $id, 'property', 'text') WriteToConsoleAndLog("id inner =: " & $ClipData) WriteToConsoleAndLog("id value =: " & $ClipData2) WriteToConsoleAndLog("id text =: " & $ClipData3) However this is console output with the findElement returning no match _WD_FindElement ==> No match [8] : Parameters: Strategy=xpath Selector=//*[@id="MhrCore-homeCardTitle--ooo"] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=innerText __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=value __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=text x inner =: x value =: x text =: __WD_Post ==> No match [8] : HTTP status = 404 _WD_FindElement ==> No match [8] : Parameters: Strategy=xpath Selector=//*[@id="MhrCore-homeCardTitle--ooo"] StartNodeID=Default Multiple=Default ShadowRoot=Default _WD_GetElementById ==> No match [8] : Parameters: ID=MhrCore-homeCardTitle--ooo __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=innerText __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=value __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=text id inner =: id value =: id text =: >Exit code: any ideas?
Danp2 Posted September 29, 2023 Posted September 29, 2023 You'll need to figure out why it is failing. A couple of things to check are frames and shadowroots. Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted October 2, 2023 Author Posted October 2, 2023 Can you provide an example to test a frame and shadowroot?
mLipok Posted October 2, 2023 Posted October 2, 2023 (edited) 1 hour ago, CaptainBeardsEyesBeard said: Can you provide an example to test a frame and shadowroot? https://github.com/mlipok/Au3WebDriver-testing/edit/main/wd_testing_Example.au3 #Region - - wait for all frames to finish loading the page and get infromation about all frames Local $aFrameList = _WD_FrameList($__g_sSession, True, 1000, Default) If @error Then Return SetError(@error, @extended, 0) ; show all frames _ArrayDisplay($aFrameList, 'Frames - get frame list as array', 0, 0, Default, $sArrayHeader) #EndRegion - wait for all frames to finish loading the page and get infromation about all frames Edited October 2, 2023 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
Danp2 Posted October 2, 2023 Posted October 2, 2023 You could use _WD_FrameListFindElement to attempt to locate the element within a frame. If found, use the information returned in your actual script along with _WD_FrameEnter and _WD_FindElement. Do NOT use _WD_FrameListFindElement in your final script. As far as shadow roots, you would generally determine this by looks at the HTML source code (you could do the same for frames). Latest Webdriver UDF Release Webdriver Wiki FAQs
seadoggie01 Posted October 4, 2023 Posted October 4, 2023 iFrames are my nemesis. I have a couple of tips... Don't work with them, find the iFrame, get the src property, and navigate to that URL instead. Of course, this won't always work depending on what the frame is for. Test and get your XPaths while you're viewing only the inner page (see above) Test your XPaths in JavaScript (at least at first) as it's faster. Open the console and use: document.evaluate("//your/xpath", document).iterateNext(). You'll get an error or an element printed out It's sometimes easier to execute a script in JS instead of figuring it out in AutoIt Sleep on it. I swear sometimes it works. Good luck! 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
CaptainBeardsEyesBeard Posted October 10, 2023 Author Posted October 10, 2023 So I'm trying to access an element using the frame function. Am I using it correctly? $Element = _WD_FrameListFindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@id="PPL%3d966A19D6BEBAB8ED0549FAD78E168774"]/img') if @error then WriteToConsoleAndLog("-Error on _WD_FrameListFindElement") endif $v = _WD_ElementAction($sSession, $Element, 'property', 'value') $i = _WD_ElementAction($sSession, $Element, 'property', 'innerText') $t = _WD_ElementAction($sSession, $Element, 'property', 'textContent') WriteToConsoleAndLog("value Equals: " & $v) WriteToConsoleAndLog("inner Equals: " & $i) WriteToConsoleAndLog("textContent Equals: " & $t) My Console output indicates an error on the FrameListFindElement function _WD_FrameListFindElement ==> General Error [1 / 0] : > Issue with getting list of frames -Error on _WD_FrameListFindElement__WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=value __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=innerText __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=textContent value Equals: inner Equals: textContent Equals: >Exit code: 0 Time: 108.8
Danp2 Posted October 10, 2023 Posted October 10, 2023 @CaptainBeardsEyesBeard That one line of code looks ok to me. The error indicates that an issue occurred while attempting to retrieve a list of frames (_WD_FrameList). Again, _WD_FrameListFindElement shouldn't appear in your final script; it's strictly for assisting you in identifying the correct frame to access. We have no way of knowing why this is occurring due to the limited information provided by you. These are my suggestions at this time -- Make sure that you are using the most recent release of the UDF Try running the DemoFrames example in wd_demo, which uses the same function Provide a short script that we can run to observe / replicate the issue (use a different website if needed) Provide a more detailed log so that we can see the process from start to finish Regards, Dan Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted October 11, 2023 Author Posted October 11, 2023 (edited) So I tried to put this into a function that way you can test if it works This is the Webdriver Frame test. Is this the correct way to get a frame then push the value into a variable? Also if you have any advice to improve this function that'd be great Func Webdriver_Test_Frame($sSession, $Xpath, $TextToBeTested, $TestDescription, $X, $Y ) Local $ClipData Local $aLocationOfElement = _WD_FrameListFindElement($sSession, $_WD_LOCATOR_ByXPath, $Xpath) if @error then WriteToConsoleAndLog("---ERROR on Webdriver_Test_Frame(). First error catch statement.") Sleep(4000) WriteToConsoleAndLog("---Log: Waiting 4 secs") Local $aLocationOfElement = _WD_FrameListFindElement($sSession, $_WD_LOCATOR_ByXPath, $Xpath) if @error then WriteToConsoleAndLog("---ERROR 2nd error on Webdriver_Test_Frame(). 2nd error catch statement.") WriteToConsoleAndLog("---Log: Reverting to mouse clicks") ClickALocation_ThenCopyTheSelection($X, $Y, 3) $ClipData = ClipGet() EndIf Else WriteToConsoleAndLog("---Log: Success on getting _WD_FrameListFindElement() ") ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : $aLocationOfElement (" & UBound($aLocationOfElement) & ")=" & @CRLF & _ArrayToString($aLocationOfElement) & @CRLF) _ArrayDisplay($aLocationOfElement, @ScriptLineNumber & ' $aLocationOfElement', 0, 0, Default, $sArrayHeader) ;******Here I would put the element returned from the frame into $ClipData so something like.. $ClipData = _WD_ElementAction($sSession, $aLocationOfElement, 'property', 'value') endif TestVariableContainsInClipBoardOne($ClipData, $TextToBeTested, $TestDescription) EndFunc This was my console output where it fails to get the frame twice then reverts to mouseclicks _WD_ExecuteScript ==> Success [0] __WD_FrameList_Internal ==> Success [0] : Parameters: Level=null IsHidden=False Timeout=Default _WD_FrameList ==> Not found [13 / 0] : Parameters: ReturnAsArray=True iDelay=1000 iTimeout=Default Information: List of frames is empty. Was not able to check "calling frame". _WD_FrameListFindElement ==> General Error [1 / 0] : > Issue with getting list of frames ---ERROR on Webdriver_Test_Frame(). First error catch statement. ---Log: Waiting 4 secs__WD_Post ==> Success [0] : HTTP status = 200 _WD_ExecuteScript ==> Success [0] __WD_FrameList_Internal ==> Success [0] : Parameters: Level=null IsHidden=False Timeout=Default _WD_FrameList ==> Not found [13 / 0] : Parameters: ReturnAsArray=True iDelay=1000 iTimeout=Default Information: List of frames is empty. Was not able to check "calling frame". _WD_FrameListFindElement ==> General Error [1 / 0] : > Issue with getting list of frames ---ERROR 2nd error on Webdriver_Test_Frame(). First error catch statement. ---Log: Reverting to mouse clicks Double or triple clicking to copy selection of text ---LOG:TestVariableContainsInClipBoardOne function > $ClipData equals: Holiday entitlement summary Test Passed: Holiday Entitlement screen - "Holiday entitlement summary" headerThe following is in the clipboard matches the value expected Holiday entitlement summary>Exit code: 0 Time: 164.4 Edited October 11, 2023 by CaptainBeardsEyesBeard
Danp2 Posted October 11, 2023 Posted October 11, 2023 Based on the console output, I can only conclude that the website doesn't contain frames. Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted October 12, 2023 Author Posted October 12, 2023 Thanks. Is there a way to cycle through the entire HTML document? Say for example I want to find out if "testData" is on the page? Is there a way to do that?
Danp2 Posted October 12, 2023 Posted October 12, 2023 There are a couple of options -- Use _WD_GetSource to retrieve the pages source and then search it Using _WD_ExecuteScript, you could either perform the check directly in JS or retrieve the desired text and then perform the search in AutoIt Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted October 13, 2023 Author Posted October 13, 2023 I suppose if some elements are popoulated dynamically by javascript they wouldn't be picked up by getting the _WD_GetSource?
Danp2 Posted October 13, 2023 Posted October 13, 2023 I believe so, which is why I included the 2nd option above. Latest Webdriver UDF Release Webdriver Wiki FAQs
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now