Redd500 Posted May 9, 2018 Share Posted May 9, 2018 Alright, so I've been working with geckodriver and Firefox now, and I need to submit a bug to them about a very specific case that I'm dealing with. In order to get the trace log to them, I need to push geckodriver's output to a .log file, but for some reason AutoIt keeps screwing it up. The code I run is as follows: _WD_Option("Driver", "C:\Path\To\geckodriver.exe") _WD_Option("Port", 4444) _WD_Option("DriverParams", '-vv >C:\Path\To\geckodriver.log') Local $oId = _WD_Startup() Which then gives me the error: error: Found argument '>geckodriver.log' which wasn't expected, or isn't valid in this context USAGE: geckodriver.exe -v For more information try --help This is a problem because if I run the command that's being generated in a cmd window myself, then it runs the geckodriver.exe fine and outputs to the log file as I specified. This might not actually be a problem with your UDF, but with AutoIt itself because I only get this problem using AutoIt's Run() function. Link to comment Share on other sites More sharing options...
Danp2 Posted May 9, 2018 Author Share Posted May 9, 2018 @Redd500 I took a quick look at this, but didn't get the same error as you. What version of geckodriver are you using? The issue I encountered is that the redirection to the log file resulted in the command window containing the geckodriver immediately closed. To address your immediate need, you could either copy / paste the log data from the geckodriver console or you could manually launch the webdriver and skip the call to _WD_Startup. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Redd500 Posted May 9, 2018 Share Posted May 9, 2018 @Danp2 This is because the '>log file' silences geckodriver and outputs it into a log file rather than into the console. I got the error through running the code after compiling it into a .exe using Aut2Exe and its /console flag and then running the .exe through the command prompt. I generally use this for my own testing purposes so I can see where things go wrong using ConsoleWrite() or to view any errors that get written. Anyways, I managed to get it running using 2 batch files to make it run asynchronously with the log file being created, because I need to run it in Windows Task Scheduler for full automation. Thanks for the suggestion, it got me what I needed. Shame I couldn't use AutoIt though. Link to comment Share on other sites More sharing options...
Danp2 Posted May 9, 2018 Author Share Posted May 9, 2018 I understand about the log file redirection. However, it does compute for me that this would stop the console app from running. I'm guessing that it has something to do with the webdriver running directly in the console that was created by the Run command. The solution is already outlined in the help file -- Quote To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE) ; don't forget " " before "/c" I have implemented this change in _WD_Startup and it now works as I would expect. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CYCho Posted May 10, 2018 Share Posted May 10, 2018 I thoguht that _WD_Alert($session, 'status') would return True only if any alert message existed. In the following code, the first MsgBox shows 'True' and the second MsgBox shows an empty string (is it really an empty string?) when no MsgBox is expected. Do I misunderstand these functions? #include "wd_core.au3" Local $sDesiredCapabilities SetupChrome() _WD_Startup() $Session = _WD_CreateSession($sDesiredCapabilities) MsgBox(0,'',_WD_Alert($Session, 'status')) If _WD_Alert($Session, 'gettext') <> "" Then MsgBox(0,'',_WD_Alert($Session, 'gettext')) EndIf _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path=' & @ScriptDir & '\chrome.log') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars"] }}}}' EndFunc zPlayer - A Small Audio and Video Player Link to comment Share on other sites More sharing options...
Danp2 Posted May 10, 2018 Author Share Posted May 10, 2018 @CYCho The initial status check is returning incorrect information when using Chrome because the it returns a different HTTP status code than the UDF is expecting. I will need to research this further to determine how to best comply with the W3C specs. On the gettext issue, I believe it is returning an object, which would explain why your code is acting this way. Some additional error checking in the UDF will take care of this. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CYCho Posted May 10, 2018 Share Posted May 10, 2018 Maybe I can use StringLen(_WD_Alert($session, 'gettext')) to check existence of an alert message. zPlayer - A Small Audio and Video Player Link to comment Share on other sites More sharing options...
Danp2 Posted May 11, 2018 Author Share Posted May 11, 2018 @CYCho Here's a revised wd_core.au3, which is my initial attempt to resolve the issues you identified with _WD_Alert. Please test the changes and let me know if you encounter any additional issues. Thanks, Dan Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CYCho Posted May 11, 2018 Share Posted May 11, 2018 @Danp2 Thank you so much for prompt attention. It works perfect. zPlayer - A Small Audio and Video Player Link to comment Share on other sites More sharing options...
Danp2 Posted May 11, 2018 Author Share Posted May 11, 2018 Thanks for the feedback. Let me know if you encounter any issues with these changes. FWIW, I opened a bug report for the incorrect status code with Chromedriver. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CYCho Posted May 11, 2018 Share Posted May 11, 2018 The new UDF was fine with the test code above, but in my actual application it seems not right. I will give it a further test and come back with details. Unfortunately I have to go out now and it will be several hours until I can come back. zPlayer - A Small Audio and Video Player Link to comment Share on other sites More sharing options...
CYCho Posted May 11, 2018 Share Posted May 11, 2018 I tested the new UDF in working application and found that: 1. _WD_Alert($session, 'status') produces "False" regardless of the existence of an alert message. 2. _WD_Alert($session, 'gettext') produces an empty string regardless of the existence of an alert message. 3. _WD_Alert($session, 'accept') works properly. zPlayer - A Small Audio and Video Player Link to comment Share on other sites More sharing options...
Danp2 Posted May 11, 2018 Author Share Posted May 11, 2018 @CYCho Please try this revised version. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CYCho Posted May 11, 2018 Share Posted May 11, 2018 @Danp2 Yes, the revised version works exactly as expected. A job well done! Thank you so much. zPlayer - A Small Audio and Video Player Link to comment Share on other sites More sharing options...
horphi Posted May 24, 2018 Share Posted May 24, 2018 Hi, i´m not know how to select a text string within a textwindow. this works _WD_ExecuteScript($sSession, 'return document.getElementsByTagName('p')[1].innerHTML;') __WD_Post: URL=HTTP://127.0.0.1:4444/session/fc4b43b3-2c7b-4ce1-92fb-660e2d017aab/execute/sync; $sData={"script":"return document.getElementsByTagName('p')[1].innerHTML; ", "args":[[]]} __WD_Post: StatusCode=200; ResponseText={"value":"test2"} _WD_ExecuteScript: {"value":"test2"} But this not _WD_ExecuteScript($sSession, 'document.getElementsByTagName('p')[1].select;') __WD_Post: URL=HTTP://127.0.0.1:4444/session/fc4b43b3-2c7b-4ce1-92fb-660e2d017aab/execute/sync; $sData={"script":" document.getElementsByTagName('p')[1].select; ", "args":[[]]} __WD_Post: StatusCode=200; ResponseText={"value":null} _WD_ExecuteScript: {"value":null} In the w3school description is a example LINK --> select() with brackets. If i execute the function without brackets, i got the Status Code 200 back but nothing is selected. If i excute the function with brackets, i got the status code 500 _WD_ExecuteScript($sSession, 'document.getElementsByTagName('p')[1].select();') _WD_ExecuteScript: {"value":{"error":"javascript error","message":"TypeError: document.getElementById(...).select is not a function","stacktrace":"execute_script @, line 0\ninline javascript, line 1\nsrc: \"undefined\"\nStack:\n}} Can someone explain to me what i don´t understand again??? Many thanks horphi Link to comment Share on other sites More sharing options...
Danp2 Posted May 24, 2018 Author Share Posted May 24, 2018 2 minutes ago, grzesiek said: I think the select method is for the input elements. ^ This. The p element doesn't have a select function. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
horphi Posted May 25, 2018 Share Posted May 25, 2018 jepp you are right. I changed the script based on that Select <p> document.getElementsByTagName('p')[1].click(function(){var range ;range = document.createRange();range.selectNodeContents(document.getElementsByTagName('p')[0]);window.getSelection().addRange(range)}); _WD_ExecuteScript($sSession, 'document.getElementsByTagName('p')[1].click(function(){var range ;range = document.createRange();range.selectNodeContents(document.getElementsByTagName('p')[1]);window.getSelection().addRange(range)});') __WD_Post: URL=HTTP://127.0.0.1:4444/session/87406f69-c375-4321-9e48-c0860f247cd2/execute/sync; $sData={"script":"document.getElementsByTagName('p')[1].click(function(){var range ;range = document.createRange();range.selectNodeContents(document.getElementsByTagName('p')[1]);window.getSelection().addRange(range)});", "args":[[]]} __WD_Post: StatusCode=200; ResponseText={"value":null} _WD_ExecuteScript: {"value":null} But the selection them self is still outstanding.... :-( Link to comment Share on other sites More sharing options...
Danp2 Posted May 25, 2018 Author Share Posted May 25, 2018 A few questions for you -- Can you explain why you need to select this text? What's your end goal here? Have you tried running your javascript code directly in the browsers console? This is what I would recommend until you get it working. Then test it using _WD_ExecuteScript. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
horphi Posted May 25, 2018 Share Posted May 25, 2018 (edited) 7 hours ago, Danp2 said: A few questions for you -- Can you explain why you need to select this text? What's your end goal here? Have you tried running your javascript code directly in the browsers console? This is what I would recommend until you get it working. Then test it using _WD_ExecuteScript. Hi, i´ve got it. I´m not firm with the syntax, but this workes fine! 1. i dive into the frame 2. i select my paragraph 3. i leave the frame _WD_Window($sSession, 'frame', '{"id":0}') _WD_ExecuteScript($sSession, '{var range = document.createRange();range.selectNodeContents(document.getElementById('test'));var sel = window.getSelection();sel.addRange(range);}') _WD_Window($sSession, 'parent', '{"id":0}') Best regards, horphi Edited May 25, 2018 by horphi Link to comment Share on other sites More sharing options...
horphi Posted June 4, 2018 Share Posted June 4, 2018 Hello together, does somebody know, whether it´s possible to check to progress of loading a webpage and execute script first after 100% load of webpage? BR horphi Link to comment Share on other sites More sharing options...
Recommended Posts