How to Verify Dialog Text in Chrome
I would like to verify the text of a Dialog that is fired from the browser during test execution.
Solution
This could be achieved in a coded solution. The code will both handle the dialog and verify the text within it. What is used to handle this in Chrome is AutomationElement Class. A new AutomationElement object is retrieved for the dialog window referenced by the specified window handle and its node is located. The location of the text may vary depending on the machine used for execution though this is handled in the if..else statement.
Note:
This code requires an assembly reference to be added in the project for the following libraries:
- Telerik.TestStudio.Core.dll
- UIAutomationClient.dll
- UIAutomationTypes.dll
- System.Windows.Forms.dll
The last three could be usually found in 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\'.
Ensure you add the following using or Imports statements to the top of the code-behind file.Scroll to the top of the code file and add these lines: