selenium 仅在管道中引发StaleElementReferenceException

yqkkidmi  于 2023-02-04  发布在  其他
关注(0)|答案(1)|浏览(117)

我有一个测试在我们的azure管道中运行,每次运行都失败(结果是大约一半的时间),并出现StaleElementReferenceException。无论何时在本地运行测试(无头或其他),测试都会通过。
有趣的是,它在运行一个在多个其他测试中使用的方法时失败了,这些测试不会遇到这个问题。
我有一个调用堆栈,但我真的不知道如何去调试这个!有什么建议吗?

at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebElement.Execute(String commandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebElement.get_Displayed()
   at SeleniumExtras.WaitHelpers.ExpectedConditions.<>c__DisplayClass6_0.<ElementToBeClickable>b__0(IWebDriver driver)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition, CancellationToken token)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at GembaCloud.Tests.Pages.BasePage.BasePageActions.WaitForElementToBeClickable(By element) in C:\agent\_work\53\s\GembaCloud.Tests\Pages\BasePage.cs:line 205
   at GembaCloud.Tests.Pages.BasePage.BasePageActions.GetTable(By byTable, Int32 firstDataRowIndex) in C:\agent\_work\53\s\GembaCloud.Tests\Pages\BasePage.cs:line 259
   at GembaCloud.Tests.Pages.GembaIntelligencePage.GembaIntelligencePageActions.GetGembaIntelligenceTable() in C:\agent\_work\53\s\GembaCloud.Tests\Pages\Home\GembaIntelligencePage.cs:line 52
   at GembaCloud.Tests.Pages.GembaIntelligencePage.GembaIntelligencePageActions.ExpandGembaIntelligenceTableRow(Int32 rowNumber) in C:\agent\_work\53\s\GembaCloud.Tests\Pages\Home\GembaIntelligencePage.cs:line 79
   at GembaCloud.Tests.TestClasses.UserRolePageElementAuthorisationTests.reporting_user_should_not_have_access_to_intelligence_dropdown_create_action_button() in C:\agent\_work\53\s\GembaCloud.Tests\TestClasses\UserRolePageElementAuthorisationTests.cs:line 115

有什么明显的问题吗?谢谢!
下面是调用堆栈中项目的代码。首先是GembaIntelligencePage类:

public void ExpandGembaIntelligenceTableRow(int rowNumber)
            {
                this.ExpandTableRow(this.GetGembaIntelligenceTable(), rowNumber);
            }

            public IList<IWebElement> GetGembaIntelligenceTable()
            {
                return this.GetTable(_elements.byGembaIntelligenceTable, 1);
            }

第二个BasePage类:

protected IList<IWebElement> GetTable(By byTable, int firstDataRowIndex)
            {
                //firstDataRowIndex is so we only return the table rows that we need
                this.WaitForElementToBeClickable(byTable);
                IWebElement table = _driver.FindElement(byTable);

                IList<IWebElement> listOfDataTableRows = table.FindElements(By.CssSelector("tr")).Skip(firstDataRowIndex -1).ToList();

                return listOfDataTableRows;
            }

            protected void WaitForElementToBeClickable(By element)
            {
                WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
                wait.Until(ExpectedConditions.ElementToBeClickable(element));
            }
nimxete2

nimxete21#

将超时值更改为更高的值(例如从10更改为30),并告诉我们它是否有效:

WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));

相关问题