在自动化测试中,表格控件的操作问题是常见问题,尤其是对一些第三方表格控件的测试问题,例如C1的TrueDBGrid:
//通过设置行属性值来达到选择行的目的,通过Item值来读取行数据:
if VarToStr(w2.Item[1].Item[0].OleValue) = ‘张三’ then
begin
Log.Message(‘张三的成绩为:’ + varToStr(w2.Item[1].Item[1].OleValue));
// 如果数据符合条件,则把该行设置为选中状态
W2.Row := 1;
end;
另外,在.NET标准控件DataGridView中选择某个单元格所在的数据行的方法如下:
For I:=0 to DataGridView.Rows.Count -1 do
Begin
If VarToStr(DataGridView.Rows.Item[I].Cells.Item[0].Value) = ‘08年度培训大纲’ then
Begin
DataGridView.set_CurrentCell(DataGridView.Rows.Item[I].Cells.Item[0]);
// 这句很重要,否则选择不生效
DataGridView.Click(0,0);
// …
End;
End;