2016-11-21 134 views
2
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包管理器 請幫助解決無法找到NgModel

+0

您是否使用安裝了.NET包量角器'安裝,包裝Protractor'? –

+0

如果可能,請粘貼元素的html代碼片段。 – lauda

+0

回答

-2

只是嘗試element(by.model("vm.system.systemdescription")).sendKeys('jkgf);

你有一個錯字在你的命令的SendKeys應與小case「S」而不是「S開頭「

希望這有助於..

+0

注意:這是C# - 'SendKeys()'是正確的。 – alecxe

+0

謝謝@Danny。但是沒有錯別字。在C#中,僅限大寫 - 按照pascal Casing編碼標準。 –

+0

ngDriver.FindElement(NgByModel.Name(「vm.system.systemdescription」))。SendKeys(「jkgf」);也不起作用。 –