C# 如何通过Selenium和Webdriver提高执行速度
在脚本执行期间,测试速度非常慢,而不知道原因 这是我的剧本:C# 如何通过Selenium和Webdriver提高执行速度,c#,selenium,selenium-webdriver,webdriver,webdriverwait,C#,Selenium,Selenium Webdriver,Webdriver,Webdriverwait,在脚本执行期间,测试速度非常慢,而不知道原因 这是我的剧本: driver.Navigate().GoToUrl(url); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20); driver.FindElement(By.LinkText("Register Here")).Click(); new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Un
driver.Navigate().GoToUrl(url);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
driver.FindElement(By.LinkText("Register Here")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
(By.XPath("//div[@class='loader-wrapper ng-trigger ng-trigger-visibilityChanged ng-animating']"))));
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Organization Type'])[2]/following::select[1]")).Click();
new SelectElement(driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Organization Type'])[2]/following::select[1]"))).SelectByText("Hospital");
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Organization Type'])[2]/following::button[1]")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
(By.XPath("//div[@class='loader-wrapper ng-trigger ng-trigger-visibilityChanged ng-animating']"))));
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Phone Number'])[1]/following::button[1]")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
(By.XPath("//div[@class='loader-wrapper ng-trigger ng-trigger-visibilityChanged ng-animating']"))));
try
{
Assert.AreEqual("Title is Required.", driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Title'])[1]/following::span[1]")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
关于如何加快测试速度的任何建议?加快脚本/程序的一个简单步骤是:
- 删除隐式等待的所有实例,如下所示:
- 您正在广泛使用WebDriverWait,即显式等待
这就是正在发生的事情,但我首先需要隐式超时,因为网站需要时间加载,并且给了我一个错误。。至于显式等待,我不知道如何解决这个问题,因为我有一个加载器,这个加载器掩盖了另一个元素。所以你建议我做的事,而不是重复显式等待和隐式等待
ImplicitWait
,很快就会死于非命。不要再依赖隐式等待
。使用定制的显式等待
满足您的所有需求。加载器可以用更简单的方法解决。我的加载器方法是不可见的:wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.XPath(“//div[@class='Loader-wrapper-ng触发器ng触发器visibilityChanged ng动画“]);我在不止一个页面中有一个加载器,因此我需要添加以上方法中的不止一个。也许您太早了,无法实现您最重要问题的第一个可用解决方案。你需要等待一段时间,等待投稿人对你的问题做出好的回答。好的,我刚刚重新接受了答案。但仍然需要更好的解决方案。正如您在这里提到的,我可以通过使用显式而不是隐式来避免测试的缓慢?