无法找到NgModel

时间:2016-11-21 08:15:13

标签: c# angularjs selenium protractor ngmodel

    driver.FindElement(By.XPath("//textarea[@ng-model='vm.system.systemdescription']")).SendKeys("abc"); //is able to find element. 
Whereas if do same thing using ngDriver i'm getting 

> async timeout exception or javascript Invalid operation exception 

    ngDriver.FindElement(NgBy.Model("vm.system.systemdescription")).SendKeys("jkgf"); 


Also tried the following but doesn't help
ngDriver.FindElement(NgByModel.Name("vm.system.systemdescription")).SendKeys("jkgf"); also does not work.                                            

Here is d code snippet                                                                              private IWebDriver driver = new InternetExplorerDriver();
        private NgWebDriver ngDriver;
        private WebDriverWait wait;
        private Actions actions;
        private int wait_seconds = 30;

        [SetUp]
        public void InitializeBrowserToSearchEngine()
        {                   ngDriver = new NgWebDriver(driver);
            driver.Navigate().GoToUrl("req_url");
             driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(60));
            ngDriver = new NgWebDriver(driver);
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(wait_seconds));
            actions = new Actions(driver);
            Console.WriteLine("Opened Browser with the given URL");
        }
[Test]
        [Order(6)]
        public void OpenNewSystemConfig()
        {
            string url = "req_url";
            ngDriver.Url = url;
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            WebDriverWait w1 = new WebDriverWait(ngDriver, TimeSpan.FromSeconds(10));
            wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("Administration_1")));
            driver.FindElement(By.Id("Administration_1")).Click();
            wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("System_Configuration_0")));
            driver.FindElement(By.Id("System_Configuration_0")).Click();

            wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.XPath("//textarea[@ng-model='vm.system.systemdescription']")));
            Thread.Sleep(5000);
            driver.FindElement(By.XPath("//textarea[@ng-model='vm.system.systemdescription']")).SendKeys("ijfk");
            //w1.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(NgBy.Model("vm.system.systemdescription")));
            //ngDriver.FindElement(NgBy.Model("vm.system.systemdescription")).SendKeys("jkgf"); ;

            wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.XPath("//select[@data-ng-model='vm.system.SystemTypeId']")));
            driver.FindElement(By.XPath("//select[@data-ng-model='vm.system.SystemTypeId']"));
            //wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(NgBy.Model("vm.system.systemdescription")));
            //ngDriver.FindElement(NgByModel.Name("vm.system.SystemTypeId"));
            // ngDriver.FindElement(NgByModel.ClassName("form-control ng-pristine ng-untouched ng-valid ng-not-empty ng-valid-required"));
               }
  

评论的代码无效。我需要使用量角器通过ng-model和ng-binding来找到元素。由于不使用Xpath,我需要一种方法来找到没有id的元素,并且定位器可以找到角度组件,例如ng-model和ng-binding。   我还使用nuget包管理器在引用中添加了量角器   请帮忙解决

1 个答案:

答案 0 :(得分:-2)

试试element(by.model("vm.system.systemdescription")).sendKeys('jkgf);

你的命令中有一个拼写错误sendKeys应该以小案例'不'S'开头

希望这会有所帮助..