Danp2 Posted May 30, 2019 Author Share Posted May 30, 2019 50 minutes ago, Letraindusoir said: Are there any actual examples where '$sStartElement' is not empty? I don't quite understand when $sStartElement is used It's used when you want to perform an element search starting at a particular element. For example, if you want to get all the rows from a table, first you retrieve the element ID for the table. Then you use this as the starting point for your subsequent find operation, like this -- $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/table") $aRows = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//tbody/tr", $sElement, True) Letraindusoir 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Letraindusoir Posted May 30, 2019 Share Posted May 30, 2019 37 minutes ago, Danp2 said: It's used when you want to perform an element search starting at a particular element. For example, if you want to get all the rows from a table, first you retrieve the element ID for the table. Then you use this as the starting point for your subsequent find operation, like this -- $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/table") $aRows = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//tbody/tr", $sElement, True) Thank you, Dan. I basically understand.... Link to comment Share on other sites More sharing options...
Letraindusoir Posted May 30, 2019 Share Posted May 30, 2019 (edited) Post is deleted,because Find it's not a problem.... Edited May 30, 2019 by Letraindusoir Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 30, 2019 Share Posted May 30, 2019 (edited) To stay logged in after first time logged in I'm saving a local profile for the future reuse. My code is as follows: $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars","--user-data-dir=' & StringReplace(@ScriptDir, Chr(92), Chr(92) & Chr(92)) & '\\Profile 1"] }}}}' So when I run script first time, I do some checks and then log in if needed (I have to do that manually first time, it's can't be automated). After that I can easily end/start my script and authentication is there ('coz of cookies). But my problem is error suggesting to restore my last session tabs. Restore pages? Chrome didn't shut down correctly. [Restore] How can I avoid this error? I'm using this code on exit: Func _QuitChrome() _WD_Window($sSession, 'Close') _WD_DeleteSession($sSession) EndFunc Func _Exit() _QuitChrome() _WD_Shutdown() Exit EndFunc UPD: I guess --disable-features=InfiniteSessionRestore should do the trick (will test it later)?.. Edited May 30, 2019 by MONaH-Rasta Found possible sollution Link to comment Share on other sites More sharing options...
Danp2 Posted May 30, 2019 Author Share Posted May 30, 2019 @Letraindusoir Because you're doing it wrong. 😉 Seriously, you can't expect us to provide an answer to this when you haven't given sufficient details on what isn't working. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 30, 2019 Share Posted May 30, 2019 So... After some research and bunch of tests I finally have a solution to get rid of this annoying popup. I'm using chrome version 74.0.3729.169 (current) latest stable. Here is a code of function that will do the trick. $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars", "--user-data-dir=' & StringReplace(@ScriptDir, Chr(92), Chr(92) & Chr(92)) & '\\Profile 1"] }}}}' _SetPreferences() _WD_Startup() Func _SetPreferences() Local $sFileName, $sFind, $sReplace, $iRetval $sFileName = @ScriptDir & Chr(92) & 'Profile 1' & Chr(92) & 'Local State' $sFind = '"exited_cleanly":false' $sReplace = '"exited_cleanly":true' $iRetval = _ReplaceStringInFile($sFileName, $sFind, $sReplace) If $iRetval = -1 Then If TrayItemGetState($iShowNotify) = 65 Then _TrayTip('File ' & Chr(92) & 'Local State' & Chr(92) & ' was not edited! Error = ' & @error) EndIf $sFileName = @ScriptDir & Chr(92) & 'Profile 1' & Chr(92) & 'Default' & Chr(92) & 'Preferences' $sFind = '"exit_type":"Crashed"' $sReplace = '"exit_type":"None"' $iRetval = _ReplaceStringInFile($sFileName, $sFind, $sReplace) If $iRetval = -1 Then If TrayItemGetState($iShowNotify) = 65 Then _TrayTip('File ' & Chr(92) & 'Local State' & Chr(92) & ' was not edited! Error = ' & @error) EndIf EndFunc If you will have those 2 options set like this before start new session, chrome will start normally regardless of was he actually crashed or not. For some reason in most cases webdriver causing chrome set those 2 options to values like after "crash", and of course my solution is not "correct", but at least I have no popups now 😎 Link to comment Share on other sites More sharing options...
Letraindusoir Posted June 3, 2019 Share Posted June 3, 2019 How to hide the CMD interface or avoid the CMD interface when running the webdriver related Codes? Link to comment Share on other sites More sharing options...
Danp2 Posted June 3, 2019 Author Share Posted June 3, 2019 @Letraindusoir If you look at the underlying code for _WD_Startup, you'll see the Run command that launches the console app. The setting of $_WD_DEBUG controls whether the console is launched hidden or visible. So you have two options -- Set the value of $_WD_DEBUG to something other than $_WD_DEBUG_Info before calling _WD_Startup Use the function _WD_ConsoleVisible to change the console's visibility MONaH-Rasta 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Suraj18 Posted June 4, 2019 Share Posted June 4, 2019 Hi @Danp2, Thank you for the UDF. It works great !! I was trying to change the default download folder of chrome. I need to map a network drive for downloads everytime session is initiated. Could you please help. Link to comment Share on other sites More sharing options...
Danp2 Posted June 4, 2019 Author Share Posted June 4, 2019 Hi @Suraj18, Thanks for the kind words. Please share some additional details showing what you have tried thus far and the outcome. Dan Letraindusoir 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Suraj18 Posted June 4, 2019 Share Posted June 4, 2019 I am running a basic script which picks up URL, Username and Password as command line parameters and initiates a web session on a RDS server as a remote application. But the session is always initiated with default Chrome settings and maps default downloads folder to the session. So I want to map the network drive as download location every time script is executed. I am really new to AutoIT so any help is much appreciated. I am really new to AutoIT so any suggestions are welcome. The code looks like: Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' EndFunc If $CmdLine[0] <> 3 Then MsgBox($MB_OK, "Usage", "ps_palo <hostname> <username> <password>") Else palo_login($CmdLine[1],$CmdLine[2],$CmdLine[3]) EndIf Func palo_login($url,$username,$password) Local $string, $sButton $sSession = _WD_CreateSession($sDesiredCapabilities) $string= "https://" & $url _WD_Navigate($sSession,$string) ;Sleep(5000) ;_WD_LinkClickByText($sSession,"Continue to this website (not recommended).") _ChromeSetInputValueById($sSession,"user",$username) Sleep(1000) _ChromeSetInputValueById($sSession,"passwd",$password) Sleep(1000) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='submit']") _WD_ElementAction($sSession, $sButton, 'click') EndFunc ;==>PaloAlto_login() Func _ChromeSetInputValueById($sSession,$Id,$Value) Local $sElement $sElement=_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='"&$Id&"']") _WD_ElementAction($sSession,$sElement,'value',$value) EndFunc ;_WD_DeleteSession($sSession) ;_WD_Shutdown() Link to comment Share on other sites More sharing options...
Danp2 Posted June 4, 2019 Author Share Posted June 4, 2019 So it appears you haven't actually tried to change the download directory in your script. Have you done any research on this topic? A quick google search turns up lots of good links, such as this one. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Letraindusoir Posted June 4, 2019 Share Posted June 4, 2019 (edited) 21 hours ago, Danp2 said: @Letraindusoir If you look at the underlying code for _WD_Startup, you'll see the Run command that launches the console app. The setting of $_WD_DEBUG controls whether the console is launched hidden or visible. So you have two options -- Set the value of $_WD_DEBUG to something other than $_WD_DEBUG_Info before calling _WD_Startup Use the function _WD_ConsoleVisible to change the console's visibility Thank You,Dan.I See.I didn't read the UDF carefully and clearly enough. Edited June 4, 2019 by Letraindusoir Link to comment Share on other sites More sharing options...
Arlen Posted June 7, 2019 Share Posted June 7, 2019 (edited) How do I know I got multiple results from "_WD_FindElement", does it return an array (tried)? $sList = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='listing-content']") _WD_ElementAction($sSession, $sList, 'text') In this example I know there are multiple classname "listing-content" but only see text from the first one. Edited June 7, 2019 by Arlen Link to comment Share on other sites More sharing options...
Danp2 Posted June 7, 2019 Author Share Posted June 7, 2019 @Arlen _WD_FindElement will always return a single element unless you set the $lMultiple parameter to True. There's a simple example of this in wd_demo.au3 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Letraindusoir Posted June 11, 2019 Share Posted June 11, 2019 Recently, I was thinking about a question: how can I move the mouse to the location of the element after getting an Element? As shown like below: $sElem = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "Xpath_sElem") _WD_MoveMouseTo($sSession,$sElem) or _WD_SetFocus($sSession,$sElem) Link to comment Share on other sites More sharing options...
Danp2 Posted June 11, 2019 Author Share Posted June 11, 2019 @Letraindusoir See the DemoActions function in wd_demo.au3 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Letraindusoir Posted July 1, 2019 Share Posted July 1, 2019 (edited) <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal --> As shown above, can this modal box pop-up window be controlled by a custom UDF similar to _ WD_Alert? Edited July 1, 2019 by Letraindusoir Link to comment Share on other sites More sharing options...
Danp2 Posted July 1, 2019 Author Share Posted July 1, 2019 @Letraindusoir You can always write a custom function to serve a particular purpose. Have you tried using the standard webdriver UDF functions to interact with this dialog? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Letraindusoir Posted July 1, 2019 Share Posted July 1, 2019 (edited) 1 hour ago, Danp2 said: @Letraindusoir You can always write a custom function to serve a particular purpose. Have you tried using the standard webdriver UDF functions to interact with this dialog? Yes, using standard functions and specific xpath,can interact with a specific Modal_dialog_box. However, since the Modal_dialog_box is a characteristic pop-up interface, it may be more convenient and practical to encapsulate the operations For Modal_dialog_box into UDF, like _WD_Alert, can identify any Alert Pop-up. Edited July 1, 2019 by Letraindusoir Link to comment Share on other sites More sharing options...
Recommended Posts