NguyenLe Posted February 4, 2018 Share Posted February 4, 2018 6 hours ago, Danp2 said: That's not the issue. You can't click an element that wasn't found by the prior function call. You'll need to locate the element first. Also some error checking in your code would help you here as well. Can you give me an example? Link to comment Share on other sites More sharing options...
Danp2 Posted February 4, 2018 Author Share Posted February 4, 2018 @NguyenLe Just check @error after the function call, like this -- SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'http://google.com') $sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='gsfi']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value','Hello') EndIf Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
NguyenLe Posted February 4, 2018 Share Posted February 4, 2018 (edited) 10 hours ago, Danp2 said: @NguyenLe Just check @error after the function call, like this -- SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'http://google.com') $sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='gsfi']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value','Hello') EndIf I found the error. Thank for your answer. Edited February 4, 2018 by NguyenLe Link to comment Share on other sites More sharing options...
Danp2 Posted February 4, 2018 Author Share Posted February 4, 2018 New version is out on GH. @NguyenLe Be sure to check out the new _WD_WaitElement. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Gianni Posted February 4, 2018 Share Posted February 4, 2018 (edited) I've done a quick attempt to use this stuff with IE11 on Win7 and at first glance it seems to work. I've only tryed to adapt the simple test from post #2 to be used with IE. more infos here https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriversteps to do the test 1) Download the IEDriverServer.exe from here http://selenium-release.storage.googleapis.com/index.html?path=3.8/ and save it along with the other scripts 2) open IE11 settings -> security -> and set (or remove) the "protected mode" flag for each zone (The value can be on or off, as long as it is the same for every zone) 3) use this modified script for the quick test expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" Local Enum $eFireFox = 0, _ $eChrome, _ $eIE Local $aTestSuite[][2] = [["TestTimeouts", False],["TestNavigation", False],["TestElements", False],["TestScript", False],["TestCookies", False],["TestAlerts", True]] Local Const $_TestType = $eIE ; $eFireFox Local $sDesiredCapabilities Local $iIndex Local $sSession $_WD_DEBUG = True Switch $_TestType Case $eFireFox SetupGecko() Case $eChrome SetupChrome() Case $eIE SetupIE() EndSwitch _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) For $iIndex = 0 To UBound($aTestSuite, $UBOUND_ROWS) - 1 If $aTestSuite[$iIndex][1] Then ConsoleWrite("Running: " & $aTestSuite[$iIndex][0] & @CRLF) Call($aTestSuite[$iIndex][0]) Else ConsoleWrite("Bypass: " & $aTestSuite[$iIndex][0] & @CRLF) EndIf Next _WD_DeleteSession($sSession) _WD_Shutdown() Func TestTimeouts() _WD_Timeouts($sSession) _WD_Timeouts($sSession, '{"pageLoad":2000}') _WD_Timeouts($sSession) EndFunc ;==>TestTimeouts Func TestNavigation() _WD_Navigate($sSession, "http://google.com") ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF) _WD_Action($sSession, "back") ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF) _WD_Action($sSession, "forward") ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF) ConsoleWrite("Title=" & _WD_Action($sSession, 'title') & @CRLF) EndFunc ;==>TestNavigation ;_WDWindow($sSession, 'frame', '{"id":nullelse Func TestElements() Local $sElement, $aElements, $sValue _WD_Navigate($sSession, "http://google.com") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib1']") If @error = $_WD_ERROR_NoMatch Then $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib']") EndIf $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/input", '', True) _ArrayDisplay($aElements) _WD_ElementAction($sSession, $sElement, 'value', "testing 123") Sleep(500) _WD_ElementAction($sSession, $sElement, 'text') _WD_ElementAction($sSession, $sElement, 'clear') Sleep(500) _WD_ElementAction($sSession, $sElement, 'value', "abc xyz") Sleep(500) _WD_ElementAction($sSession, $sElement, 'text') _WD_ElementAction($sSession, $sElement, 'clear') Sleep(500) _WD_ElementAction($sSession, $sElement, 'value', "fujimo") Sleep(500) _WD_ElementAction($sSession, $sElement, 'text') _WD_ElementAction($sSession, $sElement, 'click') _WD_ElementAction($sSession, $sElement, 'Attribute', 'text') $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib']") $sValue = _WD_ElementAction($sSession, $sElement, 'property', 'value') ConsoleWrite('value = ' & $sValue & @CRLF) EndFunc ;==>TestElements Func TestScript() _WD_ExecuteScript($sSession, "return arguments[0].second;", '{"first": "1st", "second": "2nd", "third": "3rd"}') _WD_Alert($sSession, 'Dismiss') EndFunc ;==>TestScript Func TestCookies() _WD_Navigate($sSession, "http://google.com") _WD_Cookies($sSession, 'Get', 'NID') EndFunc ;==>TestCookies Func TestAlerts() ConsoleWrite('Alert Detected => ' & _WD_Alert($sSession, 'status') & @CRLF) _WD_ExecuteScript($sSession, "alert('testing 123')") ConsoleWrite('Alert Detected => ' & _WD_Alert($sSession, 'status') & @CRLF) ConsoleWrite('Text Detected => ' & _WD_Alert($sSession, 'gettext') & @CRLF) _WD_Alert($sSession, 'sendtext', 'new text') ConsoleWrite('Text Detected => ' & _WD_Alert($sSession, 'gettext') & @CRLF) Sleep(5000) _WD_Alert($sSession, 'Dismiss') EndFunc ;==>TestAlerts Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('DriverParams', '--log trace') _WD_Option('Port', 4444) $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}' EndFunc ;==>SetupGecko 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 }}}}' EndFunc ;==>SetupChrome Func SetupIE() _WD_Option('Driver', 'IEDriverServer.exe') _WD_Option('Port', 5555) _WD_Option('DriverParams', '--log-file=' & @ScriptDir & '\IE.log') $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}' EndFunc ;==>SetupIE Edited February 5, 2018 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Danp2 Posted February 5, 2018 Author Share Posted February 5, 2018 (edited) @Chimp Thanks for posting your results with IE. P.S. This seems to be the same as the MS Edge driver, found here. Edited February 5, 2018 by Danp2 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
NguyenLe Posted February 7, 2018 Share Posted February 7, 2018 @Danp2 _WD_WaitElement() is not working if I Compile au3 to exe. Link to comment Share on other sites More sharing options...
ban64 Posted February 7, 2018 Share Posted February 7, 2018 I've been looking through the samples but couldn't find what I was looking for. How do we connect to an existing session? Link to comment Share on other sites More sharing options...
Danp2 Posted February 7, 2018 Author Share Posted February 7, 2018 5 hours ago, NguyenLe said: @Danp2 _WD_WaitElement() is not working if I Compile au3 to exe. So it works when run via Scite but not when compiled to an EXE? Can you share some code that demonstrates the issue? Also, what version of Autoit are you using? Which browser are you using for testing? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted February 7, 2018 Author Share Posted February 7, 2018 2 hours ago, ban64 said: I've been looking through the samples but couldn't find what I was looking for. How do we connect to an existing session? This is controlled by the parameters passed to the specific driver when launched. If you look here, you will see that the Mozilla Geckodriver supports the option "--connect-existing". You would use _WD_Option to set the DriverParams option before calling _WD_Startup. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
horphi Posted February 7, 2018 Share Posted February 7, 2018 Hello, first of all thx @Danp2 for this great WD UDF. It helps a lot for repeating work and speed in browsing. :-) One question: i start a new firefox session and i´m missing my already included add-ons, which i like to refer during execution of some scripts. Is there a way to start a new session wit FF Browser including Add-ons? many thx, horphi Link to comment Share on other sites More sharing options...
horphi Posted February 7, 2018 Share Posted February 7, 2018 On 2/4/2018 at 2:19 AM, Danp2 said: @NguyenLe Just check @error after the function call, like this -- SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'http://google.com') $sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='gsfi']") If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'value','Hello') EndIf What i do, if i cannot really identify an unique object, i switch to wd_script for instance... Func _attach() ;--> open attachment dialog $sinputATT = "document.getElementsByName('attachment')[0].click();" _WD_ExecuteScript($sSession, $sinputATT) EndFunc ;==>_attach BR Link to comment Share on other sites More sharing options...
Danp2 Posted February 7, 2018 Author Share Posted February 7, 2018 53 minutes ago, horphi said: Is there a way to start a new session wit FF Browser including Add-ons? This would be controlled using the DesiredCapabilities parameter that gets passed to _WD_CreateSession. Each driver has it's own implementation method. You can gather more details at these links -- https://github.com/mozilla/geckodriver https://sites.google.com/a/chromium.org/chromedriver/capabilities horphi 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
NguyenLe Posted February 8, 2018 Share Posted February 8, 2018 (edited) @Danp2 Thank you I found the error in my code, I fixed it. Edited February 8, 2018 by NguyenLe Danp2 1 Link to comment Share on other sites More sharing options...
CYCho Posted February 8, 2018 Share Posted February 8, 2018 Hi, When I want to invoke a search box in the web driver session, sending "^F" or "!F" is not working. It works outside of the script, but it doesn't inside the script. I'm going around by clicking the setting button and sending "F". Am I doing anything wrong? $_WD_DEBUG = False SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.88countryclub.co.kr/") $hwnd = WinWaitActive("88") WinSetState($hwnd, "", @SW_MAXIMIZE) Sleep(1000) Send("^F") zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
Danp2 Posted February 8, 2018 Author Share Posted February 8, 2018 Seems to work if you use ControlSend instead of Send -- ControlSend($hwnd, "", "", "^f") You should also be able to do with webdriver commands, but I haven't tested it. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CYCho Posted February 9, 2018 Share Posted February 9, 2018 ControlSend($hwnd, "", "", "^f") does not work either. I can't find a suitable webdriver command in your UDFs. zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
Danp2 Posted February 9, 2018 Author Share Posted February 9, 2018 4 minutes ago, CYCho said: ControlSend($hwnd, "", "", "^f") does not work either. I can't find a suitable webdriver command in your UDFs. It did in my testing. Here's the complete code -- #include "wd_core.au3" Local $sDesiredCapabilities $_WD_DEBUG = False SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.88countryclub.co.kr/") $hwnd = WinWaitActive("88") WinSetState($hwnd, "", @SW_MAXIMIZE) Sleep(1000) ControlSend($hwnd, "", "", "^f") 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 }}}}' EndFunc swagger 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CYCho Posted February 9, 2018 Share Posted February 9, 2018 Yes, it does. I don't know how I sent "^F" instead of "^f". It works with both simple Send() and ControlSend(). Thanks a lot. zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
Danp2 Posted February 11, 2018 Author Share Posted February 11, 2018 FWIW -- Released another update on Github. 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