繁体   English   中英

在表格单元格C#中设置ComboBox值

[英]Set the ComboBox value in a Table Cell C#

我正在做的项目有点像机器人,我抓住了应用程序的过程(用于一些自动化的问答测试),然后在应用程序中添加值和编辑值,然后查看输出是否符合预期。

好了,我已经获得了应用程序窗口(称为窗口),并且正在寻找一个已添加到其他应用程序中的DataGridView项。 我知道它叫做“ dataGridView1”,并且我正在使用的UI界面(SpecFlow和White.Core)不支持从另一个应用程序中获取DataGridView项。

作为解决方法,我将DataGridView项作为表。 现在,问题了。 我试图在数据网格视图中设置一个单元格值,其中该单元格包含一个ComboBox,而该表不支持选择。 每当我执行Cell.SetValue(string)时,它将临时设置该值,直到我在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);

    }

对于Q&A自动化,我强烈建议Selenium ...您可以制作一个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中可以像我在Selenium中那样指定CSS选择或XPath

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM