Jury Posted August 24, 2020 Share Posted August 24, 2020 (edited) I can now get the innertext contents of the table I require using the WebDriver (it is a bit slow compared to IETableWriteToArray): SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'https://courts.ie/judgments') ;$Handle = _WD_Window($sSession, 'window', '') _WD_Window($sSession, "Maximize") If @error Then Exit SetError(4, @error) Local $aResult = _WD_GetTable($sSession, "//table[@class='table alfresco-table']") _DebugArrayDisplay($aResult) resulting in: 31/07/2020|O'Donoghue -v- Laois County Council||High Court|Barr J.|24/08/2020 31/07/2020|Reidy -v- An Bord Pleanala||High Court|Barr J.|24/08/2020 31/07/2020|Fitzpatrick & anor -v- Minister for Agriculture Food and the Marine & anor||Supreme Court|McKechnie J.|24/08/2020 ... but I can't find a way of either getting the full (outertext?) which includes the hyperlinks etc. within the table or failing that is there a way using the WebDriver to get all the links within the table much as _IELinkGetCollection? I'd guess it is a type of _WD_FindElement or a _WD_FindElement identified by a wild card Xpath - I'm I on the correct path? Joe Edited August 24, 2020 by Jury mistake Link to comment Share on other sites More sharing options...
Danp2 Posted August 24, 2020 Share Posted August 24, 2020 I'm sure the function can be optimized, perhaps by using Javascript to retrieve the text. Feel free to submit suggested improvements. As far as retrieving links, you would use something like this -- _WD_ElementAction($sSession, $sElement, "Attribute", "href") where $sElement is the result returned by _WD_FindElement. You can use _WD_FindElement to returned multiple matching elements by setting the $lMultiple parameter to True Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted August 24, 2020 Share Posted August 24, 2020 FYI... this mod using StringSplit on the retrieved row text runs magnitudes faster. However, the results are different from the original function (caused by a hidden column) -- Func _WD_GetTable_RowText($sSession, $sBaseElement) Local Const $sFuncName = "_WD_GetTable" Local $aElements, $iLines, $iColumns, $iRow, $iColumn, $sRowText, $aText ; Get the table element $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sBaseElement) If @error <> $_WD_ERROR_Success Then Return SetError(__WD_Error($sFuncName, @error, "HTTP status = " & $_WD_HTTPRESULT), $_WD_HTTPRESULT, "") ; Retrieve it's HTML $sHTML = _WD_ElementAction($sSession, $sElement, "Property", "outerHTML") If @error <> $_WD_ERROR_Success Then Return SetError(__WD_Error($sFuncName, @error, "HTTP status = " & $_WD_HTTPRESULT), $_WD_HTTPRESULT, "") $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sBaseElement & "/tbody/tr[1]/td", "", True) ; Retrieve the number of table columns by checking the first table row If @error <> $_WD_ERROR_Success Then Return SetError(__WD_Error($sFuncName, @error, "HTTP status = " & $_WD_HTTPRESULT), $_WD_HTTPRESULT, "") $iColumns = UBound($aElements) $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sBaseElement & "/tbody/tr", "", True) ; Retrieve the number of table rows If @error <> $_WD_ERROR_Success Then Return SetError(__WD_Error($sFuncName, @error, "HTTP status = " & $_WD_HTTPRESULT), $_WD_HTTPRESULT, "") $iLines = UBound($aElements) Local $aTable[$iLines][$iColumns] ; Create the AutoIt array to hold all cells of the table ConsoleWrite($iLines & " / " & $iColumn & @crlf) For $i = 0 To $iLines - 1 $sRowText = _WD_ElementAction($sSession, $aElements[$i], "Property", "innerText") If @error <> $_WD_ERROR_Success Then Return SetError(__WD_Error($sFuncName, @error, "HTTP status = " & $_WD_HTTPRESULT), $_WD_HTTPRESULT, "") $aText = StringSplit($sRowText, @TAB) For $j = 1 To $aText[0] $aTable[$i][$j-1] = $aText[$j] Next Next Return $aTable EndFunc I think the fastest method will be find the element and then retrieve it's complete outerHTML. After that, process the HTML with StringRegExp to obtain the desired information. Found some good info in this thread , but haven't implemented it yet. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Jury Posted August 24, 2020 Author Share Posted August 24, 2020 Danp2, Thanks for coming back on this it'll be a great help I'm sure as I re-write all my IE based programs to other browsers for the future. Don't know if I'm good enough to add to the WebDriver project but if I stumble into something generally useful I'll post it in the correct topic. Joe Link to comment Share on other sites More sharing options...
Danp2 Posted August 25, 2020 Share Posted August 25, 2020 Here's a solution using @Chimp's _HtmlTable2Array UDF -- #include "wd_core.au3" #include "_HtmlTable2Array.au3" ; https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ Local $sDesiredCapabilities, $sSession, $sElement, $sHTML, $aTable SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'https://courts.ie/judgments') ; Get the table element $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='table alfresco-table']") ; Retrieve it's HTML $sHTML = _WD_ElementAction($sSession, $sElement, "Property", "outerHTML") $aTable = _HtmlTableGetWriteToArray($sHTML) _ArrayDisplay($aTable) _WD_DeleteSession($sSession) _WD_Shutdown() Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('DriverParams', '--log trace') _WD_Option('Port', 4444) $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}' EndFunc Gianni 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Jury Posted August 29, 2020 Author Share Posted August 29, 2020 Danp2, Great that works a treat! Joe Link to comment Share on other sites More sharing options...
Danp2 Posted August 29, 2020 Share Posted August 29, 2020 @Jury Check out yesterday's update to the UDF. 😉 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Jury Posted August 29, 2020 Author Share Posted August 29, 2020 Thanks again Joe Link to comment Share on other sites More sharing options...
samibb Posted December 2, 2020 Share Posted December 2, 2020 Dear Danp2 what i shuld right? thanks _WD_GetTable($sSession, $sBaseElement) What is $sBaseElement ? Link to comment Share on other sites More sharing options...
Danp2 Posted December 2, 2020 Share Posted December 2, 2020 @samibb If you check out the source code for the function, this can be found in the function header -- ; $sBaseElement - XPath of the table to return Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
samibb Posted December 6, 2020 Share Posted December 6, 2020 Dear @Danp2 the script set value name in text _WD_setelementvalue($sSession,$sTKT,$Name) this one is working ,but _WD_ElementAction($sSession,$sSearch,'click') some time working and some time not working. any ideas many Thanks Func send_Name($Name) $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_FrameEnter($sSession, 1) Local $sTKT = _WD_GetElementByName($sSession, 'aFSearchPAXParameter') Local $sSearch = _WD_GetElementByid($sSession, 'btnSearchId') MsgBox(0,'$sSearch',$sSearch) _WD_ElementAction($sSession,$sTKT,'clear') _WD_setelementvalue($sSession,$sTKT,$Name) _WD_ElementAction($sSession,$sSearch,'click') Link to comment Share on other sites More sharing options...
Danp2 Posted December 6, 2020 Share Posted December 6, 2020 @samibb Your best option is to try to identify the cause yourself. Review the results from Scite output panel to identify why the command is failing to perform the desired action. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
SimonJames1234 Posted December 7, 2020 Share Posted December 7, 2020 Hi all, I hope someone can help with WEBDriver UDF, I need help selecting from a drop down menu using the _WD_SetDropDownOption, I have tried multiple options but it is still not selecting the required option. below is the HTML i am working with Thanks in advance $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@id="summaries"]/div/form/div[2]/div[1]/div[3]/div/div/div/div/div/div[1]/div[1]') _WD_SetDropDownOption($sSession, $sElement, 2, 2) Link to comment Share on other sites More sharing options...
samibb Posted December 7, 2020 Share Posted December 7, 2020 expandcollapse popup>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\11003813\Desktop\AutoIT\VIP.au3" /UserParams +>14:37:09 Starting AutoIt3Wrapper v.16.612.1119.0 SciTE v.3.6.6.0 Keyboard:00000409 OS:WIN_81/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\11003813\Desktop\AutoIT\VIP.au3 +>14:37:09 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\11003813\Desktop\AutoIT\VIP.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop _WD_IsLatestRelease: True _WD_IsLatestRelease ==> Success _WDStartup: OS: WIN_81 WIN32_NT 9600 _WDStartup: AutoIt: 3.3.14.2 _WDStartup: WD.au3: 0.3.1.0 (Up to date) _WDStartup: WinHTTP: 1.6.4.2 _WDStartup: Driver: chromedriver.exe _WDStartup: Params: --verbose --log-path="C:\Users\11003813\Desktop\AutoIT\chrome.log" _WDStartup: Port: 9515 __WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "localhost:9222"}}}} __WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"87.0.... _WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"87.0.4280.88","chrome":{"chromedriverVersion":"86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378})"},"goog:chromeOptions":{"debuggerAddress":"localhost:9222"},"pageLoadStrategy":"normal","platformName":"","proxy":{},"setWindowRect":false,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:virtualAuthenticators":true},"sessionId":"e7355c7faacc0c4e01b21f3d8e6746be"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/e7355c7faacc0c4e01b21f3d8e6746be/frame; $sData={"id":1} __WD_Post: StatusCode=200; ResponseText={"value":null}... _WD_Window: {"value":null}... __WD_Post: URL=HTTP://127.0.0.1:9515/session/e7355c7faacc0c4e01b21f3d8e6746be/element; $sData={"using":"xpath","value":"//*[@name=\"aFSearchPAXParameter\"]"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"f925c91e-1489-44c0-a160-e86bedf78b06"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"f925c91e-1489-44c0-a160-e86bedf78b06"}} _WD_GetElementByName ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/e7355c7faacc0c4e01b21f3d8e6746be/element; $sData={"using":"xpath","value":"//*[@id=\"btnSearchId\"]"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"a2aff7c9-6d15-4592-94f6-7d40af379158"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"a2aff7c9-6d15-4592-94f6-7d40af379158"}} _WD_GetElementById ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/e7355c7faacc0c4e01b21f3d8e6746be/element/f925c91e-1489-44c0-a160-e86bedf78b06/clear; $sData={"id":"f925c91e-1489-44c0-a160-e86bedf78b06"} __WD_Post: StatusCode=200; ResponseText={"value":null}... _WD_ElementAction: {"value":null}... __WD_Post: URL=HTTP://127.0.0.1:9515/session/e7355c7faacc0c4e01b21f3d8e6746be/element/f925c91e-1489-44c0-a160-e86bedf78b06/value; $sData={"id":"f925c91e-1489-44c0-a160-e86bedf78b06", "text":"ALMANSOURI/ABDULHADI"} __WD_Post: StatusCode=200; ResponseText={"value":null}... _WD_ElementAction: {"value":null}... _WD_SetElementValue ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/e7355c7faacc0c4e01b21f3d8e6746be/element/a2aff7c9-6d15-4592-94f6-7d40af379158/click; $sData={"id":"a2aff7c9-6d15-4592-94f6-7d40af379158"} __WD_Post: StatusCode=200; ResponseText={"value":null}... _WD_ElementAction: {"value":null}... the response is normal , 😰 Link to comment Share on other sites More sharing options...
Danp2 Posted December 7, 2020 Share Posted December 7, 2020 @samibb The function _WD_SetDropDownOption is not included in the UDF, so you may want to let others know where you found it. Also, the output you posted doesn't match the earlier lines of code. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
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