首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium WebDriver异常WebDriver对远程WebDriver服务器的请求在x秒后超时

Selenium WebDriver异常WebDriver对远程WebDriver服务器的请求在x秒后超时
EN

Stack Overflow用户
提问于 2022-04-19 16:48:11
回答 2查看 2.6K关注 0票数 0

因此,我正在尝试使用C#和NUnit建立一个Selenium测试套件。一切似乎都正常,直到我的测试时间开始超过6分钟的长度。目前,任何超过6分钟的测试都会以标题中所述的错误结束。"OpenQA.Selenium.WebDriverException :在90秒后向远程WebDriver服务器请求URL http://localhost:52821/session/f88e9cd6e93e8a3ef98796aaf87d14dd/url超时。

然而,正在测试的页面都是实时的生产网站,没有在本地主机上进行测试。

到目前为止,我已经尝试将默认的命令超时增加到不同的时间间隔,包括30、60、90、120和180秒,这只会使测试报告错误所需的时间更长。有时测试运行6分钟,其他时间停止13分钟或介于两者之间的任何地方。通常,它甚至会到达测试的最后一页,并将错误抛到那里。奇怪的是,如果我把书页分开,它就可以正常运行了。但是,当测试以这种方式失败时,色驱动程序不会退出,页面将保持打开状态,刷新功能就像等待请求一样。

我从字面上看了所有其他相关的问题,他们似乎都解决了自己的问题(就像它刚刚消失了一样),或者做了一些工作,但这并不能真正解决问题,而是让他们仍然可以进行测试。我想知道这是怎么回事。

我的chrome浏览器是最新版本: 100.0.4896.127。chromedriver也是最新版本,也是100.*版本的最新版本。我重新安装了两个和相同的问题。我使用的所有Nuget包也都是最新的。

我用firefox尝试了geckodriver,问题也在那里。

我不确定这是硒问题,还是我的测试套件设计上的问题,甚至是我的个人电脑的问题,因为它有时会冻结。所以我会把所有我认为相关的东西都包括进去。

我一直在使用单例方法( fyi) 代码

设置

代码语言:javascript
复制
[SetUpFixture]
    [TestFixture]
    public class Setup
    {
        IWebDriver driver;        

        //Runs before ANY test is run
        //provies a place to set up configs for a testing env
        [OneTimeSetUp]
        public void RunBeforeAllTests()
        {
            driver = WebDriverSingleton.GetInstance();      
        }

        //Will run after every test has been completed
        //clean up
        [OneTimeTearDown]
        public void RunAfterAllTests()
        {                              
            WebDriverSingleton.Terminate();
        }
    }

司机

代码语言:javascript
复制
public class Driver
    {
        public IWebDriver driver;

        public Driver()
        {
            this.driver = WebDriverSingleton.GetInstance();            
        }

        public void Start()
        {
            driver = WebDriverSingleton.GetInstance();
            driver.Manage().Window.Maximize();
        }
        public void End()
        {
            driver.Close();
            //WebDriverSingleton.Terminate();
        }
        public void GoTo(string url)
        {
            this.driver.Url = url;
        }

        public IWebElement GetElementBy(string method, string selector)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(20000));
            try
            {
                switch (method)
                {
                    case "tag":
                        return wait.Until(ExpectedConditions.ElementIsVisible(By.TagName(selector)));
                    case "xpath":
                        return wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(selector)));
                    case "css":
                        return wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector(selector)));
                    case "id":
                        return wait.Until(ExpectedConditions.ElementIsVisible(By.Id(selector)));
                    default:
                        return null;
                }
            }catch (Exception ex)
            {
                Assert.Fail("FAILURE! last page: " + this.driver.Url + "\n" + ex.Message);
                return null;
            }
            
        }

        public string GetTextBy(string method, string selector)
        {
            WebDriverWait wait = new(driver, TimeSpan.FromMilliseconds(10000));
            //{
                // didnt seem to work :/
            //    PollingInterval = TimeSpan.FromSeconds(5),
            //};
        
            switch (method)
            {
                case "tag":
                    return wait.Until(ExpectedConditions.ElementIsVisible(By.TagName(selector))).Text;
                case "xpath":
                    return wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(selector))).Text;
                case "css":
                    return wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector(selector))).Text;
                case "id":
                    return wait.Until(ExpectedConditions.ElementIsVisible(By.Id(selector))).Text;
                default:
                    return null;
            }
        }    
    }

辛格尔顿

代码语言:javascript
复制
public sealed class WebDriverSingleton
    {
        private static IWebDriver instance = null;
        private WebDriverSingleton() { }

        public static IWebDriver GetInstance()
        {
            if(instance == null)
            {
                ChromeOptions options = new();
                options.BrowserVersion = "100.0.4896.6000";
                options.AddArgument("no-sandbox");
                instance = new ChromeDriver(Environment.CurrentDirectory, options, TimeSpan.FromSeconds(90));
            }

            return instance;
        }
        
        public static void Terminate()
        {
            instance.Close();
            instance.Quit();
            instance.Dispose();
            instance = null;
        }

    }

问题所在的测试类

代码语言:javascript
复制
[TestFixture]
    public class PowerSupplyTests
    {
        readonly Driver driver = new Driver();
        private readonly Common Common = new();        
        public List<ProductPage> ProductPages { get; set; }
        public string TestDomain { get; set; }
        public string CurrLang { get; set; }
        // for now only 1 language comparison can be run at a time
        public List<string> LanguagesToTest = new List<string>()
        {
            /*"DE","ES",  */ "FR"/*, "IT"*/
        };
        public List<string> ProductPageListOldTechSpecTable = new List<string>()
        {
            "/products/industrial-power-supply/quint-1-phase-xt.shtml",
            "/products/industrial-power-supply/quint-3-phase.shtml",
            //"/products/industrial-power-supply/trio-3-phase.shtml"
        };
        public List<string> ProductPageListBasicDataTable = new List<string>() 
        {
            "/products/industrial-din-rail-power-supplies.shtml",            
        };
        public List<string> ProductPageListSingleProduct = new List<string>()
        {
            "/products/industrial-power-supply/quint-high-input.shtml",
            "/products/industrial-power-supply/quint-ps-12dc-12dc-8-29050078.shtml",
            "/products/industrial-power-supply/quint-ps-12dc-24dc-5-23201318.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-12dc-15-29046088.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-12dc-20-28667218.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-1.3-pt-29095758.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-1.3-sc-29045978.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-10-29046018.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-2.5-29095768.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-2.5-sc-29045988.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-20-29046028.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-3.5-28667478.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-3.8-pt-29095778.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-3.8-sc-29045998.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-40-28667898.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-24dc-5-29046008.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-48dc-10-29046118.shtml",
            "/products/industrial-power-supply/quint-ps-1ac-48dc-20-28666958.shtml",//here for IT
            "/products/industrial-power-supply/quint-ps-1ac-48dc-5-29046108.shtml",
            "/products/industrial-power-supply/quint-ps-24dc-12dc-8-23201158.shtml",
            "/products/industrial-power-supply/quint-ps-24dc-24dc-10-23200928.shtml",
            "/products/industrial-power-supply/quint-ps-24dc-24dc-10-co-23205558.shtml",
            "/products/industrial-power-supply/quint-ps-24dc-24dc-20-23201028.shtml",//
            "/products/industrial-power-supply/quint-ps-24dc-24dc-20-co-23205688.shtml",
            "/products/industrial-power-supply/quint-ps-24dc-24dc-5-23200348.shtml",
            "/products/industrial-power-supply/quint-ps-24dc-24dc-5-co-23205428.shtml",
            "/products/industrial-power-supply/quint-ps-24dc-48dc-5-23201288.shtml",
            "/products/industrial-power-supply/quint-ps-48dc-24dc-5-23201448.shtml",
            "/products/industrial-power-supply/quint-ps-48dc-48dc-5-29050088.shtml",
            "/products/industrial-power-supply/quint-ps-60-72dc-24dc-10-29050098.shtml",
            "/products/industrial-power-supply/quint-ps-60-72dc-24dc-10-co-29050118.shtml",
            "/products/industrial-power-supply/quint-ps-96-110dc-24dc-10-29050108.shtml",
            "/products/industrial-power-supply/quint-ps-96-110dc-24dc-10-co-29050128.shtml",
            "/products/industrial-power-supply/step-ps-1ac-12dc-1.5-28685678.shtml",
            "/products/industrial-power-supply/step-ps-1ac-12dc-1.5-fl-28685548.shtml",
            "/products/industrial-power-supply/step-ps-1ac-12dc-1-28685388.shtml",
            "/products/industrial-power-supply/step-ps-1ac-12dc-3-28685708.shtml",
            "/products/industrial-power-supply/step-ps-1ac-12dc-5-28685838.shtml",
            "/products/industrial-power-supply/step-ps-1ac-15dc-4-28686198.shtml",
            "/products/industrial-power-supply/step-ps-1ac-24dc-0.5-28685968.shtml",
            "/products/industrial-power-supply/step-ps-1ac-24dc-0.75-28686358.shtml",
            "/products/industrial-power-supply/step-ps-1ac-24dc-0.75-fl-28686228.shtml",
            "/products/industrial-power-supply/step-ps-1ac-24dc-1.75-28686488.shtml",
            "/products/industrial-power-supply/step-ps-1ac-24dc-2.5-28686518.shtml",
            "/products/industrial-power-supply/step-ps-1ac-24dc-3.5-29049458.shtml",
            "/products/industrial-power-supply/step-ps-1ac-24dc-3.8-c2lps-28686778.shtml",
            "/products/industrial-power-supply/step-ps-1ac-24dc-4.2-28686648.shtml",
            "/products/industrial-power-supply/step-ps-1ac-48dc-2-28686808.shtml",//
            "/products/industrial-power-supply/step-ps-1ac-5dc-16.5-28685418.shtml",
            "/products/industrial-power-supply/step-ps-1ac-5dc-2-23205138.shtml",
            "/products/industrial-power-supply/step-ps-48ac-24dc-0.5-28687168.shtml",
            "/products/industrial-power-supply/trio-dc-dc-high-input.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-12dc-10-29031588.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-12dc-5-c2lps-29031578.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-24dc-10-29031498.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-24dc-10-b+d-29031458.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-24dc-20-29031518.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-24dc-3-c2lps-29031478.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-24dc-5-29031488.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-24dc-5-b+d-29031448.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-48dc-10-29031608.shtml",
            "/products/industrial-power-supply/trio-ps-2g-1ac-48dc-5-29031598.shtml",
            "/products/industrial-power-supply/uno-2-phase.shtml",
            "/products/industrial-power-supply/uno-dc-dc.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-12dc-100w-29029978.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-12dc-30w-29029988.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-15dc-100w-29030028.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-15dc-30w-29030008.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-15dc-55w-29030018.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-24dc-100w-29029938.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-24dc-150w-29043768.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-24dc-240w-29043728.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-24dc-30w-29029918.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-24dc-60w-29029928.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-24dc-90w-c2lps-29029948.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-48dc-100w-29029968.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-48dc-60w-29029958.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-5dc-25w-29043748.shtml",
            "/products/industrial-power-supply/uno-ps-1ac-5dc-40w-29043758.shtml"
        };

        [SetUp]
        public void Start()
        {
            driver.Start();
            ProductPages = new List<ProductPage>();
        }
        [Test]
        public void TestAllPages()
        {
            LanguagesToTest.ForEach((lang) =>
            {
                CurrLang = lang;
                switch (lang)
                {
                    case "DE":
                        TestDomain = Common.GermanDomain;
                        break;
                    case "ES":
                        TestDomain = Common.SpanishDomain;
                        break;
                    case "FR":
                        TestDomain = Common.FrenchDomain;
                        break;
                    case "IT":
                        TestDomain = Common.ItalianDomain;
                        break;
                }
                ProductPageListBasicDataTable.ForEach((p) =>
                {
                    ProductPage newPage = new ProductPage(driver, p);
                    TestDocumentationTab(newPage);
                    TestOrderDetailsTabBasicTable(newPage);
                });
                ProductPageListOldTechSpecTable.ForEach((p) =>
                {
                    ProductPage newPage = new ProductPage(driver, p);
                    TestDocumentationTab(newPage);
                    TestOrderDetailsTabOldSpecTable(newPage);
                });
                ProductPageListSingleProduct.ForEach((p) =>
                {
                    ProductPage newPage = new ProductPage(driver, p);
                    TestDocumentationTab(newPage);
                    TestOrderDetailTabSingleProduct(newPage);
                });
            });
        }    

        public void TestDocumentationTab(ProductPage productPage)
        {
            productPage.GoToProduct(Common.EnglishDomain);
            productPage.OpenDocumentationTab();
            string enSrc = productPage.CaptureIframeSrc("idoc");
            enSrc = enSrc.Substring(enSrc.IndexOf("products"));            
            productPage.GoToProduct(TestDomain);
            productPage.OpenDocumentationTab();            
            string comparisonSrc = productPage.CaptureIframeSrc("idoc");
            comparisonSrc = comparisonSrc.Substring(comparisonSrc.IndexOf("products"));
            if (!enSrc.Equals(comparisonSrc))
                Assert.Fail("Page " + productPage.PageUrl + " documentation sources do not match! \n "+ enSrc + "\n" + comparisonSrc + " failure found in lang: " + CurrLang);            
        }

        public void TestOrderDetailsTabBasicTable(ProductPage productPage)
        {
            List<Product> enProducts = new List<Product>();
            List<Product> comparisonProducts = new List<Product>();
            productPage.GoToProduct(Common.EnglishDomain);
            productPage.OpenOrderingDetailsTab();            
            enProducts = productPage.OrderDetailsTabModel.GetProductsFromBasicDataTable();            
            
            productPage.GoToProduct(TestDomain);
            productPage.OpenOrderingDetailsTab();
            comparisonProducts = productPage.OrderDetailsTabModel.GetProductsFromBasicDataTable();
            if (enProducts.Count != comparisonProducts.Count)
                Assert.Fail("Product Table Quantites do not match!");
            for (int i = 0; i < enProducts.Count; i++)
            {
                if (!enProducts[i].Equals(comparisonProducts[i]))
                    Assert.Fail("Product Tables do not match! \n" + "Failure occurred on page: " + productPage.PageUrl + "\nIn Lang: " + CurrLang);
            }            
        }
        public void TestOrderDetailsTabOldSpecTable(ProductPage productPage)
        {
            List<Product> enProducts = new List<Product>();
            List<Product> testProducts = new List<Product>();
            productPage.GoToProduct(Common.EnglishDomain);
            productPage.OpenOrderingDetailsTab();
            enProducts = productPage.OrderDetailsTabModel.GetProductsFromTechSpecDataTable();
            productPage.GoToProduct(TestDomain);
            productPage.OpenOrderingDetailsTab();
            testProducts = productPage.OrderDetailsTabModel.GetProductsFromTechSpecDataTable();
            if (enProducts.Count != testProducts.Count)
                Assert.Fail("Product Table Quantites do not match!");
            for (int i = 0; i < enProducts.Count; i++)
            {
                if (!enProducts[i].Equals(testProducts[i]))
                    Assert.Fail( CurrLang + " Product Tables do not match!");
            }
        }

        public void TestOrderDetailTabSingleProduct(ProductPage productPage)
        {
            Product enProduct = new Product();
            Product testProducts = new Product();
            productPage.GoToProduct(Common.EnglishDomain);
            productPage.OpenOrderingDetailsTab();
            enProduct = productPage.OrderDetailsTabModel.GetSingleProductFromTab();
            productPage.GoToProduct(TestDomain);
            productPage.OpenOrderingDetailsTab();
            testProducts = productPage.OrderDetailsTabModel.GetSingleProductFromTab();
            Assert.IsNotNull(enProduct.productId);
            Assert.IsNotNull(testProducts.productId);
            if (!enProduct.Equals(testProducts))
                Assert.Fail("Products Do Not Match!\nEN: " + enProduct.productId[0] + "\n" + CurrLang + ": " + testProducts.productId[0]);
        }

        [TearDown]
        public void End()
        {
            driver.End();
        }
    }

最后,错误日志

代码语言:javascript
复制
 TestAllPages
   Source: powerSupplyTests.cs line 125
   Duration: 11.1 min

  Message: 
OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:52821/session/f88e9cd6e93e8a3ef98796aaf87d14dd/url timed out after 90 seconds.
  ----> System.Threading.Tasks.TaskCanceledException : The request was canceled due to the configured HttpClient.Timeout of 90 seconds elapsing.
  ----> System.TimeoutException : The operation was canceled.
  ----> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
  ----> System.IO.IOException : Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
  ----> System.Net.Sockets.SocketException : The I/O operation has been aborted because of either a thread exit or an application request.
TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:52821/session/f88e9cd6e93e8a3ef98796aaf87d14dd/window timed out after 90 seconds.
  ----> System.Threading.Tasks.TaskCanceledException : The request was canceled due to the configured HttpClient.Timeout of 90 seconds elapsing.
  ----> System.TimeoutException : The operation was canceled.
  ----> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
  ----> System.IO.IOException : Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
  ----> System.Net.Sockets.SocketException : The I/O operation has been aborted because of either a thread exit or an application request.

  Stack Trace: 
HttpCommandExecutor.Execute(Command commandToExecute)
DriverServiceCommandExecutor.Execute(Command commandToExecute)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.set_Url(String value)
Driver.GoTo(String url) line 36
ProductPage.GoToProduct(String baseUrl) line 48
PowerSupplyTests.TestDocumentationTab(ProductPage productPage) line 172
PowerSupplyTests.<TestAllPages>b__19_3(String p) line 160
List`1.ForEach(Action`1 action)
PowerSupplyTests.<TestAllPages>b__19_0(String lang) line 157
List`1.ForEach(Action`1 action)
PowerSupplyTests.TestAllPages() line 127
--TaskCanceledException
HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
HttpCommandExecutor.Execute(Command commandToExecute)
--TimeoutException
--TaskCanceledException
HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
--IOException
AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
--SocketException
--TearDown
HttpCommandExecutor.Execute(Command commandToExecute)
DriverServiceCommandExecutor.Execute(Command commandToExecute)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.Close()
Driver.End() line 31
PowerSupplyTests.End() line 237
--TaskCanceledException
HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
HttpCommandExecutor.Execute(Command commandToExecute)
--TimeoutException
--TaskCanceledException
HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
--IOException
AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
HttpConnection.FillAsync(Boolean async)
HttpConnection.ReadNextResponseHeaderLineAsync(Boolean async, Boolean foldedHeadersAllowed)
HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
--SocketException
EN

回答 2

Stack Overflow用户

发布于 2022-04-21 13:26:49

这种行为可能是在Chrome的新版本(100)中引入的。尝试使用旧版本的Chrome和色度驱动器。

票数 1
EN

Stack Overflow用户

发布于 2022-12-01 12:16:53

这个问题在StackOverflow上已经问了很多次了。

我发现最流行的两个答案对我不起作用。

TimeSpan.FromMinutes(3));

  1. no-sandbox (这有什么用?)
  2. 新ChromeDriver(driverFolder,chromeOptions,ChromeDriver)

我已经找到了让测试运行的方法,而不是错误的失败,方法是将点击包装在一个尝试捕获中,最后一个捕获是

代码语言:javascript
复制
catch (WebDriverException)
{
    Thread.Sleep(1000);
}

使用如下结构的主代码

代码语言:javascript
复制
public BasePage Click(string css)
{
    var element = WaitForElementToBeDisplayed(css); // method wrapping driver.FindElement in a try-catch
    for (int i = 0; i < Timeout; i++)
    {
        try
        {
            element.Click();
            return this;
        }
        catch (ElementClickInterceptedException)
        {
            Thread.Sleep(1000);
        }
        catch (StaleElementReferenceException)
        {
            Thread.Sleep(1000);
        }
        catch (ElementNotInteractableException)
        {
            Thread.Sleep(1000);
        }
        catch (NoSuchElementException)
        {
            Thread.Sleep(1000);
        }
        catch (WebDriverException)
        {
            Thread.Sleep(1000);
        }
    }
    var errorText = $"Element not clicked Css={css}";
    throw new WebDriverTimeoutException(errorText);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71928501

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档