量角器似乎不会等待

时间:2017-01-31 12:01:54

标签: c# selenium protractor-net

使用Bruno Baia的量角器v0.9.2 Selenium Webdriver v3.0.1 Selenium.Webdriver.ChromeDriver v2.27.0 我面临以下问题。我是从非Angular页面登录的。当我在我的应用程序的第一个Angular页面上时,我想点击页面上NgRepeater的第一行,如下所示:

Limit  (cost=1.72..270.45 rows=11 width=1308) (actual time=0.105..0.468 rows=8 loops=1)
   ->  Nested Loop Left Join  (cost=1.72..247038.21 rows=10112 width=1308) (actual time=0.104..0.465 rows=8 loops=1)
         ->  Nested Loop  (cost=1.29..164532.13 rows=10112 width=1072) (actual time=0.071..0.293 rows=8 loops=1)
               ->  Nested Loop Left Join  (cost=0.86..116292.45 rows=10112 width=736) (actual time=0.057..0.198 rows=8 loops=1)
                     ->  Index Scan Backward using dialogs_user_id_last_message_id_d57b320e on dialogs  (cost=0.43..38842.21 rows=10112 width=102) (actual time=0.038..0.084 rows=8 loops=1)
                           Index Cond: (user_id = 9069)
                     ->  Index Scan using products_pkey on products  (cost=0.43..7.65 rows=1 width=634) (actual time=0.012..0.012 rows=1 loops=8)
                           Index Cond: (dialogs.product_id = id)
               ->  Index Scan using auth_user_pkey on auth_user t4  (cost=0.42..4.76 rows=1 width=336) (actual time=0.010..0.010 rows=1 loops=8)
                     Index Cond: (id = dialogs.participant_id)
         ->  Index Scan using messages_pkey on messages  (cost=0.44..8.15 rows=1 width=236) (actual time=0.019..0.020 rows=1 loops=8)
               Index Cond: (dialogs.last_message_id = id)
 Total runtime: 0.678 ms

当上述语句为class CarCompanies { NgWebDriver driver; [FindsBy(How = How.XPath, Using = "Bedrij")] private IWebElement linkBedrijven; public bool ContainsText(string text, string heading) { return SelecteerElement.pageContainsHeadingElementWithText(driver, text, heading); } public void ClickFirstCar() { driver.FindElements(NgBy.Repeater("dmsInstance in dmsInstanceList"))[0].Click(); } public CarCompanies(NgWebDriver driver) { this.driver = driver; PageFactory.InitElements(driver, this); } } 时,此方法正常,但如果没有此不需要的睡眠,则会显示Thread.Sleep()。司机告诉我IndexOutOfRangeException IgnoreSynchronisation = false

我做错了什么?

1 个答案:

答案 0 :(得分:-1)

当你在没有睡眠的情况下呼叫FindElements时,我猜测该元素还没有出现。在寻找之前你应该等待元素存在。

最有可能使用

driver.WaitForAngular();

将解决问题(方法等待角度完成加载)。

如果没有,您可以设置implicit waitwrite an extension to wait while finding the element

顺便说一下,在您的情况下不需要使用FindElements(By)[0],方法FindElement将返回DOM中的第一个元素。