在表格单元格C#中设置组合框值

本文关键字:组合 设置 表格 单元格 | 更新日期: 2023-09-27 18:24:14

我正在做的项目有点像机器人,我获取应用程序的流程(用于一些自动问答测试),然后在应用程序中添加值和编辑值,看看输出是否如预期。

好吧,我已经得到了应用程序窗口(称为窗口),我想得到一个DataGridView项,它已经添加到另一个应用程序中。我知道它被称为"dataGridView1",我使用的UI接口(SpecFlow和White.Core)不支持从另一个应用程序中获取DataGridView项

作为一种变通方法,我将DataGridView项作为一个表。现在,问题来了。我正在尝试在数据网格视图中设置一个单元格值,该单元格位于包含一个组合框,表不支持选择该组合框。每次我执行Cell.SetValue(字符串)时,它都会临时设置值,直到我在UI 上导航为止

所以,基本上,我的问题是,有没有任何方法可以设置一个表单元格的值,该单元格应该是一个包含组合框的DataGridView单元格?我在代码中添加了一些我希望发生的事情的注释

public void InsertValues(String price, String name)
    {
     //actually is the following
     //DataGridView Data = window.Get<DataGridView>("dataGridView1");
     //but this is not supported by the White.Core.UIItems.
        Table Data = window.Get<Table>("dataGridView1");
        int numRows = 0;
        foreach (White.Core.UIItems.TableItems.TableRow tbr in Data.Rows)
            numRows++;
 //get the last row in the table
        White.Core.UIItems.TableItems.TableRow leaseRow = Data.Rows[numRows - 1];

        White.Core.UIItems.TableItems.TableCell PriceCell = leaseRow.Cells["price_val"];
        White.Core.UIItems.TableItems.TableCell NameCell = leaseRow.Cells["name_val"];

//set the values of the various cells in the table 
        PriceCell.Click();
        PriceCell.SetValue(pricingFormulaName);
        PriceCell.Enter(pricingFormulaName);
        NameCell.Click();
        NameCell.SetValue(feeScheduleName);
        NameCell.Enter(feeScheduleName);
    }

在表格单元格C#中设置组合框值

对于Q&自动化,我强烈推荐硒。。。你可以制作一个html脚本,或者在你的情况下,一个C#应用程序来运行它。使用selenium,你可以指定

      driver.FindElement(By.XPath("//div[@id='Body']/form/div/div[2]/div[13]/div/div/div/div[2]/button")).Click();

     driver.FindElement(By.XPath("//a[contains(text(),'[add]')]")).Click();

如果它在css中,或者您可以通过ID调用它…最棒的是Selenium是开源的。。。或者,在SpecFlow中,您可以指定CSS Selection或XPath,就像我在Selenium 中所做的那样