如何使用watin从Radcombobox中选择值 [英] How to select value from Radcombobox using watin
问题描述
我正在使用watin进行自动化。现在我要访问telerik控件。
有时候我们可以找到radtextbox但我在访问RadcomboBox时遇到问题。
所以我需要从中选择项目radcombobox通过watin代码。
这个下面的行我们找到了控制ID,但是它存在为假,所以如何解决这个问题
WT.SelectList selectList = ieInstance.SelectList(WT.Find.ById(currActionStep.Name));
以下是我的整个代码,我是用于从正常下拉列表中选择项目:
i am working on automation using watin. now i am going to access telerik control.
some times we can able to find out radtextbox but i am facing problem while access RadcomboBox.
so i require to select item from radcombobox through watin code.
This below line we are finding ID of control, but it is coming exist as false, so how to salve this problem
WT.SelectList selectList = ieInstance.SelectList(WT.Find.ById(currActionStep.Name));
The below one is my whole code which i am using for select item from normal dropdown:
WT.SelectList selectList = ieInstance.SelectList(WT.Find.ById(currActionStep.Name));
// WT.SelectList selectList = ieInstance.SelectList(WT.Find.ByName(currActionStep.Name));
if (selectList != null && selectList.Exists)
{
if (selectList.Options.Count > 0)
{
foreach (WT.Option tempOption in selectList.Options)
{
string txtVal = tempOption.Text;
if (!string.IsNullOrEmpty(txtVal)) // Compare with visible option text
{
if (txtVal.Trim().Equals(currActionStep.Value.Trim()))
{
try
{
selectList.Option(currActionStep.Value.Trim()).Select();
//if (objWebControl.IsAlert || objWebControl.IsConfirm)
// HandleConfirmAlertDailog(objWebControl, ref Errormsg, ref errorcount);
ieInstance.Eval(string.Format("$('#{0}').change();", selectList.Id));
}
catch (ElementNotFoundException ex)
{
ieInstance.Eval(string.Format("$('#{0}').change();", selectList.Id));
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
log.Info("Exception occured in ProcessWebForm.SelectDropDownByText: " + ex.InnerException.ToString());
//Errormsg += ex.Message + Environment.NewLine;
}
else
{
log.Info("Exception occured in ProcessWebForm.SelectDropDownByText: " + ex.Message);
//Errormsg += ex.Message + Environment.NewLine;
}
}
selectList.Refresh();
break;
}
}
}
IEStaticInstanceHelper.IE.WaitForComplete();
var nativeElement = selectList.NativeElement as IEElement;
nativeElement.AsHtmlElement.scrollIntoView();
return Success;
}
提前致谢
}
Thanks in advance
推荐答案
('#{0}')。change();,selectList.Id));
}
catch (ElementNotFoundException ex)
{
ieInstance.Eval( string .Format(
('#{0}').change();", selectList.Id)); } catch (ElementNotFoundException ex) { ieInstance.Eval(string.Format("
('#{0}' ).change();,selectList.Id));
}
catch (Exception ex)
{
if (ex.InnerException!= null )
{
log.Info( ProcessWebForm.SelectDropDownByText中出现异常: + ex.InnerException的ToString());
// Errormsg + = ex.Message + Environment.NewLine;
}
else
{
log.Info( ProcessWebForm.SelectDropDownByText中出现异常: + ex.Message);
// Errormsg + = ex.Message + Environment.NewLine;
}
}
selectList.Refresh();
break ;
}
}
}
IEStaticInstanceHelper.IE.WaitForComplete();
var nativeElement = selectList.NativeElement as IEElement;
nativeElement.AsHtmlElement.scrollIntoView();
返回成功;
('#{0}').change();", selectList.Id)); } catch (Exception ex) { if (ex.InnerException != null) { log.Info("Exception occured in ProcessWebForm.SelectDropDownByText: " + ex.InnerException.ToString()); //Errormsg += ex.Message + Environment.NewLine; } else { log.Info("Exception occured in ProcessWebForm.SelectDropDownByText: " + ex.Message); //Errormsg += ex.Message + Environment.NewLine; } } selectList.Refresh(); break; } } } IEStaticInstanceHelper.IE.WaitForComplete(); var nativeElement = selectList.NativeElement as IEElement; nativeElement.AsHtmlElement.scrollIntoView(); return Success;
}
提前致谢
}
Thanks in advance
这篇关于如何使用watin从Radcombobox中选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!