Selenium脚本为Dynamics CRM 365帐户实体创建多个记录

时间:2017-12-02 11:28:51

标签: excel c#-4.0 selenium-webdriver dynamics-crm-365

我已经开发了一个Selenium脚本,用于使用Excel Sheet for Account实体在Dynamics CRM 365中创建多个记录,但是当我运行脚本时,CRM系统最初会自动创建一个空白记录。请在下面找到相同的屏幕截图和代码。 (noofaccountstocreate是一个用于存储整数值的变量)

             int q;
        for (q = 0; q <= noofaccountstocreate; q++)
        {
            chrome.FindElement(By.Id("account|NoRelationship|HomePageGrid|Mscrm.HomepageGrid.account.NewRecord")).Click();

            Thread.Sleep(2000);

            chrome.SwitchTo().Frame(chrome.FindElement(By.Id("contentIFrame1")));
            //Thread.Sleep(3000);

            Actions ikl_act3 = new Actions(chrome);

            ikl_act3.MoveToElement(chrome.FindElement(By.Id("name_d"))).SendKeys("Test " + q);

            //ikl_act3.Click();
            Thread.Sleep(2000);

            ikl_act3.Perform();
            Thread.Sleep(2000);

            ikl_act3.Release();
            Thread.Sleep(2000);

            chrome.FindElement(By.XPath("//*[@id='savefooter_statuscontrol']")).Click();

            Thread.Sleep(10000);
            chrome.SwitchTo().DefaultContent();

            Thread.Sleep(2000);
            chrome.FindElement(By.Id("Tabnav_accts-main")).Click();

            Thread.Sleep(2000);}

Please see image here (Selenium Multiple Addition Error)

1 个答案:

答案 0 :(得分:0)

Microsoft为Dynamics 365 here on GitHub提供了Selenium适配器。请尝试通过其API创建帐户记录。您的代码看起来像:

using (var xrmBrowser = new XrmBrowser(TestSettings.Options))
{
    xrmBrowser.LoginPage.Login(_xrmUri, _username, _password);
    xrmBrowser.GuidedHelp.CloseGuidedHelp();

    xrmBrowser.ThinkTime(500);
    xrmBrowser.Navigation.OpenSubArea("Sales", "Accounts");

    xrmBrowser.ThinkTime(2000);
    xrmBrowser.Grid.SwitchView("Active Accounts");

    xrmBrowser.ThinkTime(1000);
    xrmBrowser.CommandBar.ClickCommand("New");

    xrmBrowser.ThinkTime(4000);
    xrmBrowser.Entity.SetValue("name", "Test API Account");
    xrmBrowser.Entity.SetValue("telephone1", "555-555-5555");
    xrmBrowser.Entity.SetValue("websiteurl", "https://easyrepro.crm.dynamics.com");

    xrmBrowser.CommandBar.ClickCommand("Save & Close");
    xrmBrowser.ThinkTime(2000);
}

没有调试就很难诊断出你的问题。