Jump to content

Webdriver Test a field function


Recommended Posts

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

 

Link to comment
Share on other sites

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! 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...