CaptainBeardsEyesBeard Posted December 12, 2022 Share Posted December 12, 2022 Hi I'm creating a function to test performance times of a link. The basic function is Start timer click link wait for element to appear stop timer However I'm finding it's not waiting for the element but continuing the script? This was working the other day but then I did update the wd.au3 files Func WebDriver_PerformanceTest_ClickLinkAndTimeUntilElementAppears($sSession, $Xpath, $ElementToAppear, $TestResultText) Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. $Element = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $Xpath) _WD_ElementAction($sSession, $Element, 'click') _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $ElementToAppear) Local $fDiff = TimerDiff($hTimer) FileWrite($TestResults, @CRLF & "Performance Tests: " & $TestResultText) FileWrite($TestResults, @CRLF & " Time it took for element to appear") FileWrite($TestResults, @CRLF & " " & $fDiff) Endfunc Any pointers as to why it continues the script instead of waiting for element to appear? Link to comment Share on other sites More sharing options...
CaptainBeardsEyesBeard Posted December 12, 2022 Author Share Posted December 12, 2022 In fact this is really strange. I ran my automation a bunch more times and it seemed to continue the script. Then I just ran it and it ran perfectly 😭 I've not changed any code so why would it continue the script sometimes and not others?! Link to comment Share on other sites More sharing options...
Danp2 Posted December 12, 2022 Share Posted December 12, 2022 You'll need to review the webdriver logs and compare a successful run versus an unsuccessful one. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CaptainBeardsEyesBeard Posted December 13, 2022 Author Share Posted December 13, 2022 So this is an example where I launch the script and it fails immediately. "C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "H:\Quality Assurance\AutoIT Scripts\IMIAA\Framework\TestEnv2.au3" Error: Winactivate Outlook window > Mouse click the New email icon > Can't activate window_WD_Option ==> Success [0] : Parameters: Option=Driver Value=chromedriver.exe _WD_Option ==> Success [0] : Parameters: Option=Port Value=9515 _WD_Option ==> Success [0] : Parameters: Option=DriverParams Value=--log-path="H:\Quality Assurance\AutoIT Scripts\IMIAA\Framework\chrome.log" _WD_IsLatestRelease ==> Success [0] : True _WD_Startup: OS: WIN_10 WIN32_NT 19042 _WD_Startup: AutoIt: 3.3.14.4 _WD_Startup: Webdriver UDF: 0.11.0 (Up to date) _WD_Startup: WinHTTP: 1.6.4.2 _WD_Startup: Driver: chromedriver.exe (32 Bit) _WD_Startup: Params: --log-path="H:\Quality Assurance\AutoIT Scripts\IMIAA\Framework\chrome.log" _WD_Startup: Port: 9515 _WD_Startup: Command: "chromedriver.exe" --log-path="H:\Quality Assurance\AutoIT Scripts\IMIAA\Framework\chrome.log" _WD_Startup ==> Success [0] __WD_Post ==> Send / Recv error [6] : HTTP status = 0 _WD_CreateSession ==> Webdriver Exception [10] __WD_Delete ==> Success [0] : HTTP status = 200 _WD_DeleteSession ==> Success [0] : WebDriver session deleted >Exit code: 0 Time: 38.36 Link to comment Share on other sites More sharing options...
CaptainBeardsEyesBeard Posted December 13, 2022 Author Share Posted December 13, 2022 I put an error check on the WD Wait element and it turns out it's returning an error for each time I use it. Why would this return an error? ---------------Click Login button-------------------__WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//*[@id="root"]/div/div/div[3]/div/div[3]/form/div[3]/div/button StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=click Option=Default _WD_LoadWait ==> Success [0 / 4] : Parameters: Delay=Default Timeout=Default Element=Default DesiredState=complete : ReadyState= complete (Fully loaded) _WD_WaitElement ==> Timeout [7] : Parameters: Strategy=xpath Selector=//*[@id="covering-file-tab-MY BTKs"] Delay=Default Timeout=Default Options=Default ------ERROR: Error on _WD_WaitElement for: IMIAA > Login Screen > Click logon screen > Wait for element to appear Function where WD Wait element is used Func WebDriver_PerformanceTest_ClickLinkAndTimeUntilElementAppears($sSession, $Xpath, $ElementToAppear, $TestResultText) Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. $Element = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $Xpath) _WD_ElementAction($sSession, $Element, 'click') _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $ElementToAppear) if @error then Msgbox(16, "", "-----WD_WaitElement Error at: " & $TestResultText, 3) WriteToConsoleAndLog("------ERROR: Error on _WD_WaitElement for: " & $TestResultText) endif Local $fDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff. FileWrite($TestResults, @CRLF & "-Performance Tests: " & $TestResultText) FileWrite($TestResults, @CRLF & "-----Time it took for element to appear") FileWrite($TestResults, @CRLF & "-----" & $fDiff) WriteToConsoleAndLog( "-Performance Tests: " & $TestResultText) WriteToConsoleAndLog( "----Time it took for element to appear") WriteToConsoleAndLog( "----" & $fDiff) Endfunc Link to comment Share on other sites More sharing options...
Danp2 Posted December 13, 2022 Share Posted December 13, 2022 2 hours ago, CaptainBeardsEyesBeard said: So this is an example where I launch the script and it fails immediately. In this case, you would need to check chrome.log to determine why chromedriver failed. 2 hours ago, CaptainBeardsEyesBeard said: I put an error check on the WD Wait element and it turns out it's returning an error for each time I use it. Why would this return an error? It doesn't find the desired element before it timesout. FWIW, the default timeout is 10 seconds unless you override it. Can you provide a short reproducer so that we can test on our end? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
CaptainBeardsEyesBeard Posted December 13, 2022 Author Share Posted December 13, 2022 Quote It doesn't find the desired element before it timesout. FWIW, the default timeout is 10 seconds unless you override it. I see. It seems to fail quicker than 10 seconds but quite instantly. Do you mind providing the correct syntax for the override. I tried the below but got a failure _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $ElementToAppear [, $iDelay = 20]]) Quote Can you provide a short reproducer so that we can test on our end? Sure I'm using it in this context WebDriver_PerformanceTest_ClickLinkAndTimeUntilElementAppears($sSession, $XPath_link_to_click,$XPath_Element_to_wait_for, "Main screen > Clicking login button") and the function is defined here Func WebDriver_PerformanceTest_ClickLinkAndTimeUntilElementAppears($sSession, $Xpath, $ElementToAppear, $TestResultText) Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. $Element = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $Xpath) _WD_ElementAction($sSession, $Element, 'click') _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $ElementToAppear [, $iDelay = Default]]) if @error then Msgbox(16, "", "-----WD_WaitElement Error at: " & $TestResultText, 3) WriteToConsoleAndLog("------ERROR: Error on _WD_WaitElement for: " & $TestResultText) endif Local $fDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff. FileWrite($TestResults, @CRLF & "-Performance Tests: " & $TestResultText) FileWrite($TestResults, @CRLF & "-----Time it took for element to appear") FileWrite($TestResults, @CRLF & "-----" & $fDiff) WriteToConsoleAndLog( "-Performance Tests: " & $TestResultText) WriteToConsoleAndLog( "----Time it took for element to appear") WriteToConsoleAndLog( "----" & $fDiff) Endfunc Link to comment Share on other sites More sharing options...
Danp2 Posted December 13, 2022 Share Posted December 13, 2022 1 hour ago, CaptainBeardsEyesBeard said: I see. It seems to fail quicker than 10 seconds but quite instantly. Did you perhaps try to change the default timeout using _WD_Option? FWIW, your syntax is off, and the timeout should be supplied in milliseconds. The following is from the DemoSleep function in wd_demo -- _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//img[@class="loader-spinner ng-hide" and @ng-show="loading"]', Default, 3 * 60 * 1000) so the above should wait up to 3 minutes before timing out. P.S. You haven't posted code that we can run to reproduce the issue. One easy way to do this is to modify the UserTesting function in wd_demo to perform the desired actions. It would look something like this -- Func UserTesting() ; here you can replace the code to test your stuff before you ask on the forum Local $sURL = '<Insert your website here>' Local $sFindXpath = '<Insert first xpath here>' Local $sWaitXpath = '<Insert second xpath here>' _WD_Navigate($sSession, $sURL) _WD_LoadWait($sSession) $Element = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sFindXpath) _WD_ElementAction($sSession, $Element, 'click') _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $sWaitXpath) EndFunc ;==>UserTesting 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