HezzelQuartz Posted March 3 Posted March 3 If I have a website element below and I still don't know the transaction ID number expandcollapse popup<body id="body-overlay"> <div class="xyz-content"> <div class="container"> <div class="xyz-wrapcontent"> <div id="history" class="xyz-history-container"> <div class="xyz-history-content"> <div id="tbl" class="xyz-history-table-content"> <table class="table table-hover table-sm table-striped" style="width:100%"> <tbody> <tr> <td> <ul> <li> ::marker <strong>Transaction ID:</strong> 4537988 </li> </ul> </td> </tr> <tr> <td> <ul> <li> ::marker <strong>Transaction ID:</strong> 4537107 </li> </ul> </td> </tr> <tr> <td> <ul> <li> ::marker <strong>Transaction ID:</strong> 4537092 </li> </ul> </td> </tr> </tbody> </div> </div> </div> </div> </div> </div> </div> </body> How to use webdriver to find the transaction ID number? Thank you
Nessie Posted March 3 Posted March 3 (edited) Maybe with a regex like that? #include <Array.au3> $sRead = FileRead(@DesktopDir & "\source.txt") ;A File that contain the source code $aRegex = StringRegExp($sRead, '(?m)(?i)ID:\s*<\/strong>\s*(\d+)', 3) ;Regex _ArrayDisplay($aRegex) Hi! Edited March 3 by Nessie My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file
Danp2 Posted March 3 Posted March 3 You could try retrieving all of the list item (li) elements. Also, take a look at _WD_GetTable. Latest Webdriver UDF Release Webdriver Wiki FAQs
HezzelQuartz Posted March 3 Author Posted March 3 (edited) 11 minutes ago, Danp2 said: You could try retrieving all of the list item (li) elements. Also, take a look at _WD_GetTable. @Danp2 Could you tell me how to do that? What $sStrategy and $sSelector should I use? How to show the table or the specific result I mean above? Thank You ================================================================================================ @Nessie Is there any way so that I don't need to store the website source into text file? Edited March 3 by HezzelQuartz
Nessie Posted March 3 Posted March 3 Instead of using FileRead, just simply pass the source code of the page in a variable and use that in the StringRegExp function. My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file
Danp2 Posted March 4 Posted March 4 Did you try using the method that @SOLVE-SMART previously explained to you regarding how to identify the selector for an element? Please show us what you've tried thus far. Latest Webdriver UDF Release Webdriver Wiki FAQs
HezzelQuartz Posted March 4 Author Posted March 4 (edited) 35 minutes ago, Danp2 said: Did you try using the method that @SOLVE-SMART previously explained to you regarding how to identify the selector for an element? Please show us what you've tried thus far. @Danp2 Yes, of course This is what I tried so far expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.??????.???/") Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('Port', 4444) _WD_Option('DriverParams', '--log trace') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}' EndFunc Sleep(5000) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='close']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='btn btn-grad-orange']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='usn']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value', "xxxxxx") Sleep(1000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='pwd']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value', "yyyyyy") Sleep(1000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@class='btn btn-purple btn-block btn-xyz-submit']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='close']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='btn btn-grad-orange dropdown-toggle']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='/wallet/history/']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@src='/assets/images/wallet/history/purchase.png']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; After doing above there is a table containing several transaction ID I want to take the first one or two or three I plan to do while loop inside Edited March 4 by HezzelQuartz
SOLVE-SMART Posted March 4 Posted March 4 (edited) Hi folks 👋 , I did not see this newer thread about the topic. That's why I respond in the older thread (which was the only thread in my perspective, until I saw this one here). On 3/4/2025 at 12:30 AM, Nessie said: Instead of using FileRead, just simply pass the source code of the page in a variable and use that in the StringRegExp function. Interesting approach @Nessie. My assumption was that the html DOM structure is only a example. Your way could be okay when the webpage is pretty small - if not it could be hard to get the correct Transaction IDs through RegEx (in case the structure is more complex). But I will consider your approach in some of my use cases as a easy work-around 😅 , so thanks for the idea. On 3/4/2025 at 1:04 AM, Danp2 said: Did you try using the method that @SOLVE-SMART previously explained to you regarding how to identify the selector for an element? Please show us what you've tried thus far. Thanks @Danp2 😀 . An example on how to get the Transaction IDs is 🔗 here (the old/other thread). Update: I moved the answer now to this thread. See below. Best regards Sven Edited March 5 by SOLVE-SMART ==> AutoIt related: 🔗 GitHub, 🔗 Discord Server 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)
Solution SOLVE-SMART Posted March 5 Solution Posted March 5 (edited) Hi @HezzelQuartz , If your html DOM structure really look like your example (I guess it just a part of it), then simply use this XPath pattern: //strong/.. Explanation: //strong ==> will find 3 elements with text "Transaction ID:" //strong/.. ==> will find 3 elements with text "::marker Transaction ID: 4537988" and the other IDs //strong/parent::* ==> does the same as above, but is more explicit to write "/parent::" //strong/parent::li ==> does the same as above, but is even more explicit to write "/parent::" and the expected element "li" If you only want the get the ID numbers of each element, I would do something like this: expandcollapse popupFunc _GetTransactionIDs() Local Const $sSelector = '//strong/parent::*' Local Const $aElementsList = _FindElements($sSelector) If Not IsArray($aElementsList) Then ConsoleWrite('Oops! Handle the unexpected behavior.' & @CRLF) EndIf Local Const $aTransactionIDs = _ExtractTransactionID($aElementsList) _ArrayDisplay($aTransactionIDs) EndFunc Func _ExtractTransactionID($aElementsList) Local Const $sRegExPattern = '(\d+)' Local $aMatch For $i = 0 To UBound($aElementsList) - 1 $aElementsList[$i] = _GetElementsTexts($aElementsList[$i]) $aMatch = StringRegExp($aElementsList[$i], $sRegExPattern, 1) If Not IsArray($aMatch) Or $aMatch[0] == 0 Then ConsoleWrite('Oops! Handle the unexpected behavior.' & @CRLF) EndIf $aElementsList[$i] = $aMatch[0] Next Return $aElementsList EndFunc Func _FindElements($sSelector) Return _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sSelector, Default, True) EndFunc Func _GetElementsTexts($sElementID) Return _WD_ElementAction($sSession, $sElementID, 'text') EndFunc The _ArrayDisplay($aTransactionIDs) output should display 3 numbers (transaction ids) as list (table). Best regards Sven Edited March 5 by SOLVE-SMART ==> AutoIt related: 🔗 GitHub, 🔗 Discord Server 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)
HezzelQuartz Posted March 5 Author Posted March 5 @SOLVE-SMART Sorry, I have another question What if it is more complicated like my example below? expandcollapse popup<body id="body-overlay"> <div class="xyz-content"> <div class="container"> <div class="xyz-wrapcontent"> <div id="history" class="xyz-history-container"> <div class="xyz-history-content"> <p> Last Login: <strong>06/03/2025 5:31:40</strong> </p> <div id="tbl" class="xyz-history-table-content"> <table class="table table-hover table-sm table-striped" style="width:100%"> <tbody> <tr> <td> <ul> <li> ::marker <strong>Transaction ID:</strong> 4537988 </li> </ul> </td> </tr> <tr> <td> <ul> <li> ::marker <strong>Transaction ID:</strong> 4537107 </li> </ul> </td> </tr> <tr> <td> <ul> <li> ::marker <strong>Transaction ID:</strong> 4537092 </li> </ul> </td> </tr> </tbody> </div> </div> </div> </div> </div> </div> </div> </body> There is another strong above, but I want to get only text between strong inside <table class="table table-hover table-sm table-striped" style="width:100%"> How can I get only transaction ID without detecting "06/03/2025 5:31:40"? Is there any way I can use xpath pattern like "//strong" and something else so that it only search inside <table class="table table-hover table-sm table-striped" style="width:100%">? Thank You
Nine Posted March 5 Posted March 5 What have you tried ? Show the code you have attempted to solve your issue. Or do you want spoon-feeding solution ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
HezzelQuartz Posted March 6 Author Posted March 6 1 hour ago, Nine said: What have you tried ? Show the code you have attempted to solve your issue. Or do you want spoon-feeding solution ? @Nine Is it counted as spoon-feeding solution? If you ask me, what I have attempted to solve this issue, i stuck, no clue for this. How can you easily accuse me that I only want spoon-feeding solution? There is also another post/thread I create below he gives me example to look and learn from his github about how to deal with my problem. Is it also counted as spoon-feeding solution? I'm really sorry because I don't know that it is I only hope that if someone doesn't want to give the answer, at least give some clue so that I can learn by myself. No offense at all Thank You SOLVE-SMART 1
SOLVE-SMART Posted March 6 Posted March 6 @Nine and @HezzelQuartz , please relax, no worries. I understand your point Nine, but I also believe there is information had been lost through the different threads which are partly depend on each other. I thought HezzelQuartz needs some time to review different approaches/solutions and have to learn. As a recommendation HezzelQuartz, if you share your tryouts or just your planed next steps, it helps the community members to understand and avoid misunderstandings like this. I don't want to speak in your behave @HezzelQuartz and also not in yours @Nine. I believe it's just a misunderstanding and I wanted to point this out 😇 . Best regards Sven Nine 1 ==> AutoIt related: 🔗 GitHub, 🔗 Discord Server 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)
HezzelQuartz Posted Saturday at 08:35 AM Author Posted Saturday at 08:35 AM On 3/6/2025 at 1:52 PM, SOLVE-SMART said: @Nine and @HezzelQuartz , please relax, no worries. I understand your point Nine, but I also believe there is information had been lost through the different threads which are partly depend on each other. I thought HezzelQuartz needs some time to review different approaches/solutions and have to learn. As a recommendation HezzelQuartz, if you share your tryouts or just your planed next steps, it helps the community members to understand and avoid misunderstandings like this. I don't want to speak in your behave @HezzelQuartz and also not in yours @Nine. I believe it's just a misunderstanding and I wanted to point this out 😇 . Best regards Sven @SOLVE-SMART This is what I have tried using relative xpath expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.??????.???/") Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('Port', 4444) _WD_Option('DriverParams', '--log trace') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}' EndFunc Sleep(5000) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='close']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='btn btn-grad-orange']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='usn']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value', "xxxxxx") Sleep(1000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='pwd']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value', "yyyyyy") Sleep(1000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@class='btn btn-purple btn-block btn-xyz-submit']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='close']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='btn btn-grad-orange dropdown-toggle']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='/wallet/history/']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@src='/assets/images/wallet/history/purchase.png']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(5000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//strong/..", Default, True) for $i = 0 To UBound($sElement) - 1 $sText = _WD_ElementAction($sSession, $sElement[$i], 'text') FileWrite ( "Text.txt", $sText & @CRLF) Next The Result will be a lot of course, and not specific because the html structure is more complex, so I need to specify the array to get the result I want like below: _WD_ElementAction($sSession, $sElement[1], 'text') I tried also using absolute xpath like below: expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.??????.???/") Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('Port', 4444) _WD_Option('DriverParams', '--log trace') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}' EndFunc Sleep(5000) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='close']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='btn btn-grad-orange']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='usn']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value', "xxxxxx") Sleep(1000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='pwd']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value', "yyyyyy") Sleep(1000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@class='btn btn-purple btn-block btn-xyz-submit']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='close']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='btn btn-grad-orange dropdown-toggle']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='/wallet/history/']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(2000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@src='/assets/images/wallet/history/purchase.png']") If @error = $_WD_ERROR_Success Then _WD_ElementActionEx($sSession, $sElement, "click") Sleep(5000) EndIf ; $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[3]/div/div/div[2]/div/div[2]/table/tbody/tr[1]/td[3]/ul/li[3]/strong/..") $sText = _WD_ElementAction($sSession, $sElement, 'text') FileWrite ( "Text.txt", $sText & @CRLF) Of course, I got the result I wanted The point is, If I use relative xpath, the result will be a lot, so I need to specify the array or use conditional to detect what I want If I use absolute xpath, the result will be very specific, only one result What I want is, using relative xpath, but still get very specific result, only one, maybe with "AND"?. Thank You
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