问题描述
Ok Code下面,但我的问题是看起来我的HtmlControl对象(通过GetParent()调用设置为HtmlCell)就像对象的类型是一个窗口,不允许我向其添加搜索属性。
Ok Code Below, but my issue is it seems like my HtmlControl object (which is set to a HtmlCell via GetParent() calls) is acting like the type of the object is a window and won't allow me to add search properties to it.
我拍摄对象的屏幕截图以确保我拥有正确的HtmlCell(我这样做),并且我打印出正确的标签名称("TD"),但是尝试添加实际识别控件的内容会导致我尝试将无效的
属性设置为窗口的搜索属性时出错。
I take a screenshot of the object to ensure I have the right HtmlCell (I do), and I print out the tag name which is correct ("TD"), but attempting to add something which would actually identify the control results in an error about me trying to set an invalid property to a window's search properties.
错误[16:16:01.221]:步骤异常中的错误是[System.NotSupportedException:GetProperty of"ControlDefinition""控件类型不支持:窗口
在Microsoft.VisualStudio.TestTools.UITesting.PropertyProviderBase.ThrowNotSupportedException(Boolean isNotSupported)
在Microsoft.VisualStudio.TestTools.UITesting.WinPropertyProvider.GetPropertyValueInternal(UITestControl uiControl,String propertyName)
在Microsoft.VisualStudio.TestTools.UITesting.PropertyProviderBase.GetPropertyValue(UITestControl uiControl,String propertyName)
在Microsoft.VisualStudio.TestTools.UITesting.WinPropertyProvider.GetPropertyValue(UITestControl uiControl,String propertyName)
在Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.GetPropertyValueWrapper(UITestControl uiControl,String propertyName)
在Microsoft.VisualStudio.TestTools.UITesting.BrowserWindowPropertyProvider.GetPropertyValue(UITestControl uiTestControl,String propertyName)
在Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.GetPropertyValueWrapper(UITestControl uiControl,String propertyName)
在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyValue(String propertyName)
在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String propertyName)
在Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlControl.get_ControlDefinition()
at KeyWordDriver.Utility.Parent.getParent(HtmlControl oControl)in C:\ Automation\VSTS \KeyWordDriver \KeyWordDriver\Utility\Siblings.cs:第159行
ERROR[16:16:01.221]: Error in Step Exception was [System.NotSupportedException: GetProperty of "ControlDefinition" is not supported on control type: Window
at Microsoft.VisualStudio.TestTools.UITesting.PropertyProviderBase.ThrowNotSupportedException(Boolean isNotSupported)
at Microsoft.VisualStudio.TestTools.UITesting.WinPropertyProvider.GetPropertyValueInternal(UITestControl uiControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.PropertyProviderBase.GetPropertyValue(UITestControl uiControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.WinPropertyProvider.GetPropertyValue(UITestControl uiControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.GetPropertyValueWrapper(UITestControl uiControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindowPropertyProvider.GetPropertyValue(UITestControl uiTestControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.GetPropertyValueWrapper(UITestControl uiControl, String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyValue(String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlControl.get_ControlDefinition()
at KeyWordDriver.Utility.Parent.getParent(HtmlControl oControl) in C:\Automation\VSTS\KeyWordDriver\KeyWordDriver\Utility\Siblings.cs:line 159
  ;
如果我尝试使用我返回的对象,只要我执行类似存在检查的操作,我就会收到错误,没有输入搜索属性。除此之外,我真的想知道为什么设置为HtmlCell对象的HtmlControl只接受Window对象的有效搜索属性
。
If I attempt to use the object I return as soon as I do something like an exists check I get an error no search properties entered. That aside I really want to know why my HtmlControl which is set to a HtmlCell object is only accepting valid search properties for a Window object.
FYI传入GetParent的控件是单元格内页面上的隐藏控件,在循环的第一遍中获取它的父节点直接导致HtmlCell。
FYI the control passed into GetParent is a hidden control on the page within the cell, getting the parent of it leads directly to the HtmlCell in the 1st pass of the loop.
public class Parent
{
String sParentType = "HtmlDocument";
public Parent()
{ }
public Parent(String sType)
{
sParentType = sType;
}
public void setType(String sType)
{
sParentType = sType;
}
public HtmlControl getParent(HtmlControl oControl)
{
bool bFound = false;
HtmlControl oFinalParent = null;
HtmlControl oCurrent = oControl;
while (!bFound)
{
try
{
oCurrent = (HtmlControl)oCurrent.GetParent();
}
catch
{
return null;
}
if (sParentType.Equals("Html" + oCurrent.ControlType.ToString())) // found the parent of right type
{
GlobalVars.Logger.CaptureObject(oCurrent); // screenshot of object ensures correct object was found
bFound = true;
oFinalParent = oCurrent; // set the return objevy
oFinalParent.SearchProperties.Add(HtmlControl.PropertyNames.TagName, oCurrent.TagName);
//oFinalParent.Find(); // doesn't make think control isn't of type window.
GlobalVars.Logger.ReportDebug ("Search property TagName is [" + oFinalParent.SearchProperties[HtmlControl.PropertyNames.TagName] + "]",Logger.LOG_DEBUG);
oFinalParent.SearchProperties.Add(HtmlControl.PropertyNames.ControlDefinition, oCurrent.ControlDefinition);
//oFinalParent.SearchProperties.Add(HtmlControl.PropertyNames.TagInstance, oCurrent.TagInstance.ToString()); // also errors on window
}
}
return oFinalParent;
}
}
推荐答案
有两件事我想注意你:
1)为什么你出现上述错误:我猜,方法 getParent(HtmlControl oControl)找不到任何满意的父级(使用sParentType)。所以最后一个父是
UITestControl.Desktop (其中type = Window)。 UITestControl.Desktop没有属性ControlDefinition
1) Why you got above error: I guess, method getParent(HtmlControl oControl) doesn't find any satisfied parent (with sParentType). So the last parent isUITestControl.Desktop (which has type = Window). UITestControl.Desktop doesn't have property ControlDefinition
2)据我所知,你想获得具有你期望的classname的父类(例如,HtmlDocument,HtmlEdit ......)。但要获得此类名,您需要使用
(object)control。。 GetType()。Name
oCurrent。 ControlType .ToString()
2) As I understand, you want to get parent which has classname as you expected (for example, HtmlDocument, HtmlEdit...). But to get this class name, you need to use(object)control).GetType().Name instead ofoCurrent.ControlType.ToString()
希望它可以提供帮助你。
Hope it could help you.
这篇关于HtmlControl只接受窗口的搜索属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!