nooneclose Posted May 27, 2020 Share Posted May 27, 2020 @Danp2 That worked perfectly! Thank you. Link to comment Share on other sites More sharing options...
seadoggie01 Posted May 28, 2020 Share Posted May 28, 2020 @nooneclose I found this website super helpful when I was creating/editing Xpaths: https://www.w3schools.com/xml/xpath_intro.asp 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...
seadoggie01 Posted May 29, 2020 Share Posted May 29, 2020 _WD_WaitElement's Syntax seems to suggest that $iTimeout = -1 won't time out, but it's actually Default. (Also, do you prefer comments here or issues on GitHub? I just noticed that you said "Please post any questions, suggestions or errors in the GH&S thread." after creating an issue) 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...
Danp2 Posted May 29, 2020 Author Share Posted May 29, 2020 @seadoggie01 Looks like the function header needs updating. -1 was the original default before I started using the Default keyword. Opening an issue on GH is good for things that potentially require coding changes and you don't want them to get overlooked / forgotten in the forums. seadoggie01 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
nooneclose Posted May 29, 2020 Share Posted May 29, 2020 (edited) @Danp2 I need help again. I tried a lot of different paths (at least 10 different ones) to get the value from this element. I didn't want to bother you again after you helped me so much but I can not for the life of me figure this one out. Here is the HTML I have to work with. (I warn you now the code is not pretty) expandcollapse popup<td class="input-group" id="erpRCVDetail_Row1_Cell7" style="min-width:20px;white-space:nowrap;" onclick="document.getElementById('xmlRCVDetail').MoveTo(0);"> <div class="ui left action input"> <div title="Inventory Info" class="ui button mini pti-left-icon" onclick="document.getElementById('xmlRCVDetail');" type="button"> <i class="fa fa-building" aria-hidden="true"> </i> </div> <nobr> <div class="ui icon input"> <div class="ui input mini"> <input name="Item" disabled="disabled" class="cssTxtMedReadOnlyInputBox" id="Item" onkeydown="PTIDBControlOnKeyDown(this,event);if(!this.readOnly){if(event.keyCode==113){TextBoxZoom(this);}}" onfocus="PTIDBControlOnFocus(this);" onblur="PTIDBControlOnBlur(this);" onchange="PTIDBControlOnChange(this);" type="TEXT" size="12" maxlength="100" readonly="" placeholder="" value="13019" ptidatafld="idfItemID" ptidatarow="0" ptidatasrc="xmlRCVDetail" maxdesclength="-1" maxintlength="-1" fieldid="61332" ptidatafldreadonly="vdfReturnRO" inputaddon="INVINFO"> </div> <i class="search link icon" id="ItemZoomImage" style="DISPLAY:none" onclick="document.getElementById(this.getAttribute('PTIDataSrc')).MoveTo(this.getAttribute('PTIDataRow'));TextBoxZoom(this);" name="ItemZoomImage" ptidatarow="0" ptidatasrc="xmlRCVDetail" fieldid="61332" ;="" textid="Item"> </i> </div> </nobr> </div> </td> <div class="ui left action input"> <div title="Inventory Info" class="ui button mini pti-left-icon" onclick="document.getElementById('xmlRCVDetail').MoveTo($(this).next().children().children().children().attr('ptidatarow'));parent.Button_InvInfo();" type="button"> <i class="fa fa-building" aria-hidden="true"> </i> </div> <nobr> <div class="ui icon input"> <div class="ui input mini"> <input name="Item" disabled="disabled" class="cssTxtMedReadOnlyInputBox" id="Item" onkeydown="PTIDBControlOnKeyDown(this,event);if(!this.readOnly){if(event.keyCode==113){TextBoxZoom(this);}}" onfocus="PTIDBControlOnFocus(this);" onblur="PTIDBControlOnBlur(this);" onchange="PTIDBControlOnChange(this);" type="TEXT" size="12" maxlength="100" readonly="" placeholder="" value="13019" ptidatafld="idfItemID" ptidatarow="0" ptidatasrc="xmlRCVDetail" maxdesclength="-1" maxintlength="-1" fieldid="61332" ptidatafldreadonly="vdfReturnRO" inputaddon="INVINFO"> </div> <i class="search link icon" id="ItemZoomImage" style="DISPLAY:none" onclick="document.getElementById(this.getAttribute('PTIDataSrc')).MoveTo(this.getAttribute('PTIDataRow'));TextBoxZoom(this);" name="ItemZoomImage" ptidatarow="0" ptidatasrc="xmlRCVDetail" fieldid="61332" ;="" textid="Item"> </i> </div> </nobr> </div> <div title="Inventory Info" class="ui button mini pti-left-icon" onclick="document.getElementById('xmlRCVDetail').MoveTo($(this).next().children().children().children().attr('ptidatarow'));parent.Button_InvInfo();" type="button"> <i class="fa fa-building" aria-hidden="true"> </i> </div> <nobr> <div class="ui icon input"> <div class="ui input mini"> <input name="Item" disabled="disabled" class="cssTxtMedReadOnlyInputBox" id="Item" onkeydown="PTIDBControlOnKeyDown(this,event);if(!this.readOnly){if(event.keyCode==113){TextBoxZoom(this);}}" onfocus="PTIDBControlOnFocus(this);" onblur="PTIDBControlOnBlur(this);" onchange="PTIDBControlOnChange(this);" type="TEXT" size="12" maxlength="100" readonly="" placeholder="" value="13019" ptidatafld="idfItemID" ptidatarow="0" ptidatasrc="xmlRCVDetail" maxdesclength="-1" maxintlength="-1" fieldid="61332" ptidatafldreadonly="vdfReturnRO" inputaddon="INVINFO"> </div> <i class="search link icon" id="ItemZoomImage" style="DISPLAY:none" onclick="document.getElementById(this.getAttribute('PTIDataSrc')).MoveTo(this.getAttribute('PTIDataRow'));TextBoxZoom(this);" name="ItemZoomImage" ptidatarow="0" ptidatasrc="xmlRCVDetail" fieldid="61332" ;="" textid="Item"> </i> </div> </nobr> I need to get the value "13019" from either one of the input. I have tried: $itmNumber = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//td[@id='erpRCVDetail_Row1_Cell7']/div[@title='Inventory Info']/div[@class='ui input mini']/input[@ptidatarow='" & $i & "']") $itmNumber = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//td[@id='erpRCVDetail_Row1_Cell7']") $itmNumber = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//td[@id='erpRCVDetail_Row1_Cell7']/div[@class='ui left action input']/nobr/div[@class='ui button mini pti-left-icon']/div[@class='ui icon input']/div[@class='ui input mini']/input[@ptidatarow='" & $i & "']") $itmNumber = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//td[@id='erpRCVDetail_Row1_Cell7']/div[@class='ui left action input']/div[@class='ui icon input']/div[@class='ui input mini']/input[@ptidatarow='" & $i & "']") and so many more variations of those all to no avail. How would I go about getting that value from either one of the inputs? The error I almost always get is: _WD_FindElement: {"value":{"error":"invalid selector","message":"The specified selector is invalid.","stacktrace":""}} _WD_FindElement ==> Webdriver Exception: HTTP status = 400 Thank you for your time and help. The reason I am asking and that this is such a problem for me is because there are multiple other fields that have the same classes and ids. across the board in all those inputs, divs, and I's. The only unique ids are "ptidatafld="idfItemID" and ptidatarow="0". this is why i am trying to narrow the findelement. And those have to be combined because other fields have "ptidatafld="idfItemID" but not the same ptidatarow="0" number. Edited May 29, 2020 by nooneclose Added crucial information at the bottom Link to comment Share on other sites More sharing options...
Danp2 Posted May 29, 2020 Author Share Posted May 29, 2020 @nooneclose I would recommend that you take a look at the Chropath browser add-on. It's very helpful with these types of issues. You could also check out the Copy option from the right-click menu in Developer Tools. If gives options for xpath, css, etc. nooneclose 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
nooneclose Posted May 29, 2020 Share Posted May 29, 2020 @Danp2 I did as you suggested and I was amazed how it found the XPath so easy. However, it returned nothing __WD_Post: URL=HTTP://; $sData={"using":"xpath","value":"//div[@class='ui left action input']//div[@class='ui icon input']//div[@class='ui input mini']"} __WD_Post: StatusCode=200; ResponseText={"value":{"ELEMENT":"6be49abe-e295-4b66-beb7-b4525bfde2e0","element-6066-11e4-a52e-4f735466cecf":"6b... _WD_FindElement: {"value":{"ELEMENT":"6be49abe-e295-4b66-beb7-b4525bfde2e0","element-6066-11e4-a52e-4f735466cecf":"6be49abe-e295-4b66-beb7-b4525bfde2e0"}} __WD_Get: URL=HTTP:///session/45A5FAFB4F8C/element/e295-4b66-beb7-b4525bfde2e0/property/value __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":null}... _WD_ElementAction: {"value":null}... I used: $itmNumber = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='ui left action input']//div[@class='ui icon input']//div[@class='ui input mini']") $rArray[$i][$ac] = _WD_ElementAction($sSession, $itmNumber, 'property', 'value') to try see what it grabbed. Link to comment Share on other sites More sharing options...
Danp2 Posted May 29, 2020 Author Share Posted May 29, 2020 That xpath gives you a div element. Aren't you trying to get the input element? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
nooneclose Posted May 29, 2020 Share Posted May 29, 2020 (edited) @Danp2 I just finished editing it and got it to work right as you finished your reply. XD The working code is : $itmNumber = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='ui left action input']//div[@class='ui icon input']//div[@class='ui input mini']//input[@ptidatafld='idfItemID']") $rArray[$i][$ac] = _WD_ElementAction($sSession, $itmNumber, 'property', 'value') I can not thank you enough. This issue has been bothering me for two days now. Edited May 29, 2020 by nooneclose Danp2 1 Link to comment Share on other sites More sharing options...
sarge Posted May 29, 2020 Share Posted May 29, 2020 @Danp2Hello, I can’t solve the problem with simultaneous execution of commands by browser sessions. I am trying to find a solution in passing the command to another script. Script 1: expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $n = 5 Local $arr[1] Local $sDesiredCapabilities, $sSession, $sElement $_WD_DEBUG = $_WD_DEBUG_None _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') _WD_Startup() For $i = 1 to $n Step 1 $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--window-size=800,600"] } }}}' $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://test.com") _ArrayAdd($arr, $sSession) Next $Form1 = GUICreate("test button", 454, 204, 192, 124) $navclick = GUICtrlCreateButton("navclick", 244, 104, 161, 65, -1, $WS_EX_DLGMODALFRAME) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $navclick navclick() EndSwitch WEnd Func navclick() For $i = 1 to $n Step 1 Sleep(500) ShellExecute("navclick.exe", $arr[$i]) Next EndFunc Script 2: #include "wd_core.au3" #include "wd_helper.au3" $sSession = $CmdLine[1] _WD_Attach($sSession, "test") _WD_Navigate($sSession, "https://www.test.com/contact.html") Sleep(5500) And after compiling the second script in the navclick.exe, run .. Logically, sessions should be updated at the same time. However, I get a startup error ... 😞 Can you tell me if I'm on the right track, or am I doing the wrong thing? Link to comment Share on other sites More sharing options...
Danp2 Posted May 29, 2020 Author Share Posted May 29, 2020 @sarge You need to add this -- _WD_Option('Port', 9515) to establish the port number in each script so that it can interact with the webdriver console. Otherwise, it uses the default of 0. sarge 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
sarge Posted May 30, 2020 Share Posted May 30, 2020 @Danp2Thank you for your help! Everything worked out for me. A month ago, I did not even expect that I could figure out how to write a bot and generally in programming, but now, looking at the working script, I want to thank you again for your advice and your time! Link to comment Share on other sites More sharing options...
sarge Posted June 3, 2020 Share Posted June 3, 2020 @Danp2Hello, Can you tell me how to take a screenshot of a browser running in headless mode? Maybe there is a function that can be linked to the button? P.S. I apologize for the stupid question. Link to comment Share on other sites More sharing options...
rundak Posted June 3, 2020 Share Posted June 3, 2020 (edited) Hello, First of all thank you for this WebDriver solution @Danp2. Great work! Unfortunately I have the following problem: I am not able to clear $sObj4 value on the webpage using below code. Can I count on a little help? Many thank in advance #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sObj, $sObj2, $sObj3, $sObj4 Local $website_link = 'https://www.podatki.gov.pl/wykaz-podatnikow-vat-wyszukiwarka' SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, $website_link) $sObj = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath,"//input[@id='inputType']") ; inputbox for TIN number $sObj2 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath,"//label[@for='opt2']") ; radio button opt2 $sObj3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath,"//label[@for='vertical-checkbox2']") ; checkbox for date $sObj4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath,"//input[@id='inputType3']") ; inputbox for date??? _WD_ElementAction($sSession, $sObj2, 'click') ; Select Radio button 'NIP' Sleep(50) _WD_ElementAction($sSession, $sObj, 'value', '5260250995') ; Enter TIN number Sleep(50) _WD_ElementAction($sSession, $sObj3, 'click') ; Select checkbox related to date (enable $Obj4) Sleep(50) _WD_ElementAction($sSession, $sObj4, 'clear') ; !!!! Here is an issue with clearing element. May be incorrect element??? !!!!! Sleep(50) _WD_ElementAction($sSession, $sObj4, 'value', '01-06-2020') ; Enter a new date Func SetupChrome() _WD_Option('Driver', 'C:\Program Files (x86)\AutoIt3\Include\chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path=' & @ScriptDir & '\chrome.log') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars","user-data-dir=C:\\Users\\Computer\\AppData\\Local\\Google\\Chrome\\User Data"]}}}}' EndFunc Edited June 3, 2020 by rundak Link to comment Share on other sites More sharing options...
Danp2 Posted June 4, 2020 Author Share Posted June 4, 2020 @sarge What have you tried? AFAIK, the same functionality should even in headless mode. P.S. No idea what button to which you referred Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted June 4, 2020 Author Share Posted June 4, 2020 @rundak It's a jQuery datepicker control. You can set it's value like this -- _WD_ExecuteScript($sSession, "$('#inputType3').datepicker('setDate', '01-06-2020');") Note that there's no need to enable the control or clear it Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
rundak Posted June 4, 2020 Share Posted June 4, 2020 It works great this way. Thank you @Danp2 Link to comment Share on other sites More sharing options...
sarge Posted June 4, 2020 Share Posted June 4, 2020 @Danp2Yes, in headless mode, everything works as well. I just want to check sometimes, is everything okay? And here it is not clear how to get information, on which page is the browser located? I thought there was a function for taking a screenshot ... Link to comment Share on other sites More sharing options...
Danp2 Posted June 4, 2020 Author Share Posted June 4, 2020 1 minute ago, sarge said: I thought there was a function for taking a screenshot ... There are multiple ways to take a screenshot. Easiest is _WD_Screenshot. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
DonChunior Posted June 5, 2020 Share Posted June 5, 2020 (edited) I can't get the Tor Browser to open the search website https://duckduckgo.com/. With normal Firefox, this works fine - here's the code that works for me: _WD_Option('Driver', 'geckodriver.exe') _WD_Option('Port', 4444) _WD_Startup() Local $sSession = _WD_CreateSession('{"capabilities": {"alwaysMatch": {"moz:firefoxOptions": {"binary": "C:\\Program Files\\Mozilla Firefox\\firefox.exe"}}}}') Sleep(5000) _WD_Navigate($sSession, "https://duckduckgo.com/") And here's my code, with which I try the same in vain for the Tor browser: _WD_Option('Driver', 'geckodriver.exe') _WD_Option('Port', 9150) _WD_Startup() Local $sSession = _WD_CreateSession('{"capabilities": {"alwaysMatch": {"moz:firefoxOptions": {"binary": "C:\\Program Files\\Tor Browser\\Browser\\firefox.exe", "prefs": {"network.proxy.type": 1, "network.proxy.socks": "127.0.0.1", "network.proxy.socks_port": 9150}}}}}') Sleep(5000) _WD_Navigate($sSession, "https://duckduckgo.com/") But the code for Tor does not work. Here's the console output: _WDStartup: OS: WIN_10 WIN32_NT 18362 _WDStartup: AutoIt: 3.3.14.5 _WDStartup: WD.au3: 0.2.0.6 _WDStartup: WinHTTP: 1.6.4.1 _WDStartup: Driver: geckodriver.exe _WDStartup: Params: _WDStartup: Port: 9150 __WD_Post: URL=HTTP://127.0.0.1:9150/session; $sData={"capabilities": {"alwaysMatch": {"moz:firefoxOptions": {"binary": "C:\\Program Files\\Tor Browser\\Browser\\firefox.exe", "prefs": {"network.proxy.type": 1, "network.proxy.socks": "127.0.0.1", "network.proxy.socks_port": 9150}}}}} __WD_Post: StatusCode=0; ResponseText=0 __WD_Post ==> Send / Recv error _WD_CreateSession: 0 _WD_CreateSession ==> Webdriver Exception: HTTP status = 0 __WD_Post: URL=HTTP://127.0.0.1:9150/session//url; $sData={"url":"https://duckduckgo.com/"} __WD_Post: StatusCode=0; ResponseText=0 __WD_Post ==> Send / Recv error _WD_Navigate: 0 _WD_Navigate ==> Send / Recv error: HTTP status = 0 I would be very grateful for any help. Edited June 5, 2020 by DonChunior Link to comment Share on other sites More sharing options...
Recommended Posts