gpt4 book ai didi

c# - 如何通过Selenium和Webdriver提高执行速度

转载 作者:太空宇宙 更新时间:2023-11-03 12:11:31 24 4
gpt4 key购买 nike

在不知道原因的情况下,执行脚本时测试很慢。

这是我的脚本:

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);
}

有什么建议可以让测试更快吗?

最佳答案

让您的脚本/程序更快的一个简单步骤是:

  • 删除 ImplicitWait 的所有实例:
    • 您正在大量使用 WebDriverWait,即 Explicit Wait

根据 Explicit and Implicit Waits 的文档:

WARNING: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10 seconds and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.

关于c# - 如何通过Selenium和Webdriver提高执行速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52073952/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com