WordPress database error: [INSERT, UPDATE command denied to user '51213-2'@'10.10.20.113' for table 'wp_options']INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('_transient_doing_cron', '1714706587.0879609584808349609375', 'yes') ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)
<\/p>\n
Did you ever encounter this error while trying to retrieve a property value from an AutomationElement ? I did !<\/p>\n
Don’t worry, there is always a work-around, and I’ve found one. <\/p>\n
In this post, we’ll dig a little more into this issue and give a little example of the “Coded UI Tests” fun \ud83d\ude42<\/p>\n
<\/p>\n
Let’s create a little demo application wich contains only one control : a RichTextBox set as readonly. It may be interesting in a coded ui test to verify that the RichTextBox is really read only. <\/strong>Doing so seems pretty easy with Visual Studio :<\/p>\n [csharp][TestMethod] \/\/Assert it is really readonly By running this code, you will be disappointed to get this exception : “Property “ReadOnly” cannot be retrieved due to the current state of Edit” !<\/strong> I try to google this error but nothing is what I found \ud83d\ude41 !<\/p>\n I struggled a lot with the API and I found out that the read only property is also available via an another way<\/strong>.<\/p>\n First of all, you have to add the UIAutomationClient.dll assembly as a reference.<\/p>\n The solution is to get the native element linked to the WpfEdit which is of AutomationElement type. With it I can retrieve the the TextPattern which is supported by the RichTextBox automation peer. <\/p>\n This pattern can be use to select the whole text in the RichTextbox. Then you can retrieve the selection with the same pattern and ask for the IsReadOnly attribute value<\/strong>.<\/p>\n Pretty easy to find no ? (I am just kidding here :-s) !<\/p>\n The resulting, commented, code is here : \/\/We are in WPF so NativeElement is of AutomationElement type. \/\/Retrieve the TextPattern, \/\/use the pattern to select the whole RichTextBox \/\/ use the pattern to get the selection if (selection.Any()) \/\/This is a boolean my dear throw If you are struggling with the same kind of issue, please share it with us in the comment. You may also find intersting the list of available attributes for the TextPattern : http:\/\/msdn.microsoft.com\/en-us\/library\/ms608656.aspx<\/a><\/strong><\/p>\n
\n[xml] <RichTextBox IsReadOnly="True" Margin="3" \/>[\/xml]
\n<\/a><\/p>\n\n
\npublic void CodedUITestMethod1()
\n{
\n \/\/The target richTextBlock is of WpfEdit type
\n WpfEdit uIItemEdit = UIMap.UIPropertyXXXcannotberWindow.UIItemEdit;<\/p>\n
\n Assert.IsTrue(uIItemEdit.ReadOnly);
\n}[\/csharp]<\/p>\nHow I solved it !<\/h3>\n
\n[csharp]
\n public static bool IsReadOnly(this WpfEdit richText)
\n {
\n if (richText == null) throw new ArgumentNullException("richText");<\/p>\n
\n var element = richText.NativeElement as AutomationElement;<\/p>\n
\n var pattern = element.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
\n if (pattern == null)
\n throw
\n new InvalidOperationException("Cannot retrieve the info from the control");<\/p>\n
\n pattern.DocumentRange.Select();<\/p>\n
\n var selection = pattern.GetSelection();<\/p>\n
\n {
\n \/\/Retrieve the value of the IsReadOnly attribute
\n var attValue = selection[0]
\n .GetAttributeValue(TextPattern.IsReadOnlyAttribute);
\n if (attValue == null)
\n throw
\n new InvalidOperationException("Cannot retrieve the info from the control");<\/p>\n
\n return bool.Parse(attValue.ToString());
\n }<\/p>\n
\n new InvalidOperationException("Cannot retrieve the info from the control");
\n }
\n[\/csharp]<\/p>\n