CaptainBeardsEyesBeard Posted June 9, 2022 Posted June 9, 2022 Hi Could I get some pointers on testing web fields with the UDF driver? Currently I have these 2 functions I use for testing an element field. I'm getting some failures though so just wondering on some pointers to improve the functions It's quite simple - just uses the WD_FindElement function to get the text, then gets the innertext of that element at that point i call a function to check the variable Func WebDriver_Test_Xpath($sSession, $Xpath, $TextToBeTested, $TestDescription ) Sleep(1000) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $Xpath) $ClipData = _WD_ElementAction($sSession, $sElement, 'property', 'innerText') TestVariableContainsInClipBoardOne($ClipData, $TextToBeTested, $TestDescription) Endfunc And the TestVariableContainsInClipBoardOne() function looks like this Func TestVariableContainsInClipBoardOne($ClipData, $Input, $FieldBeingTested) if StringInStr($ClipData,$Input) Then MsgBox($MB_SYSTEMMODAL, "Test Result for field " & $FieldBeingTested, "Test " & $TestCount & " Passed: The following is in the clipboard" & $ClipData & " " & $FieldBeingTested & " matches the following value received "& $Input, 2) FileWrite($TestLog, @CRLF & "Test" & $TestCount & " Test " & $TestCount & " Passed: " & $FieldBeingTested & "The following is in the clipboard" & $ClipData & " matches the value expected " & $Input) FileWrite($TestResults, @CRLF & "Test" & $TestCount & " Test " & $TestCount & " Passed: " & $FieldBeingTested & "The clipboard" & " matches the value expected " & $Input) ; ConsoleWrite(@CRLF & "Test" & $TestCount & " Test " & $TestCount & " Passed: " & $FieldBeingTested & "The clipboard" & " matches the value expected " & $Input)) Else MsgBox($MB_SYSTEMMODAL, "Test Result for field " & $FieldBeingTested, "Test " & $TestCount & " failed: The following is in the clipboard" & $Input & " " & $FieldBeingTested & " doesn't match the following value received "& $ClipData, 2) FileWrite($TestLog, @CRLF & "Test" & $TestCount & " Test " & $TestCount & " failed: The following is in the clipboard " & $Input & " doesn't match the value expected " & $ClipData) FileWrite($TestResults, @CRLF & "Test" & $TestCount & " Test " & $TestCount & " failed: The following is in the clipboard " & $Input & " doesn't match the value expected "& $ClipData) ConsoleWrite(@CRLF & "Test" & $TestCount & " Test " & $TestCount & " failed: The following is in the clipboard " & $Input & " doesn't match the value expected "& $ClipData) EndIf $TestCount =$TestCount +1 Sleep(2000) Endfunc
Danp2 Posted June 9, 2022 Posted June 9, 2022 You should add some error checking to your first function. There's no point in trying to retrieve the innerText property if you couldn't locate the element. Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted June 10, 2022 Author Posted June 10, 2022 Thanks so I added in an error check Func WebDriver_Test_Xpath($sSession, $Xpath, $TextToBeTested, $TestDescription ) Sleep(1000) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $Xpath) if @error then Msgbox(64, "","Can't see element", 1 ) WriteToConsoleAndLog("ERROR Cannot see element for Xpath: " & $Xpath) WriteToConsoleAndLog("ERROR Test Description: " & $TestDescription) EndIf $ClipData = _WD_ElementAction($sSession, $sElement, 'property', 'innerText') TestVariableContainsInClipBoardOne($ClipData, $TextToBeTested, $TestDescription) Endfunc and it is hitting the If @error statement When I double check the xpath though it is the same as what I have in the arguement Is there anything I can do to improve it? It works on another webpage so bit confused!
Danp2 Posted June 10, 2022 Posted June 10, 2022 You are still attempting to retrieve the innerText even after failing to find the element. You should either return from the function after failing to find the element or move the remaining code into the Else portion of an If Then Else Endif statement. For more specific help, you would need to provide website, xpath, etc. so that we could observe why the element can't be found. P.S. Do you check for frames? Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted June 10, 2022 Author Posted June 10, 2022 Yeah I've not finished moving it about yet. I'll stick the below lines into an else statement What is checking frames?
Danp2 Posted June 10, 2022 Posted June 10, 2022 If the element is located within a frame, then that would explain why your attempt to locate it is failing. You would need to switch to the correct frame first using wither _WD_Window or _WD_FrameEnter. Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted June 16, 2022 Author Posted June 16, 2022 Could you demonstrate how to use this?
Danp2 Posted June 16, 2022 Posted June 16, 2022 See the DemoFrames function in wd_demo. au3 😉 Latest Webdriver UDF Release Webdriver Wiki FAQs
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