0
WebサイトをスクラップするC#アプリケーションを構築しています。この問題は、フォームを何度も送信した後にページがリロードされるために発生したと考えられます。選択リストからオプションを選択してEnterを押し、ページが新しい結果を再ロードするのを待ちます。しかし、リロード後、このエラーが発生します。OpenQA.Selenium.StaleElementReferenceException古い要素参照:要素がページ文書に添付されていません
Exception thrown: 'OpenQA.Selenium.StaleElementReferenceException' in WebDriver.dll
An exception of type 'OpenQA.Selenium.StaleElementReferenceException' occurred in WebDriver.dll but was not handled in user code
stale element reference: element is not attached to the page document (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64)
私のコードは次のようになります。
SelectElement departmentSelect = new SelectElement(driver.FindElement(By.Id("select")));
IList<IWebElement> departmentOptions = departmentSelect.Options;
foreach (IWebElement option in departmentOptions)
{
new SelectElement(driver.FindElement(By.Id("select"))).SelectByText(option.Text);
driver.FindElementById("butSearchByType").Click();
}
私も同様の試みをしました。
WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(2));
new SelectElement(driver.FindElement(By.Id("select"))).SelectByText(option.Text);
driver.FindElementById("butSearchByType").Click();
var ready = wait.Until(ExpectedConditions.ElementExists(By.Id("select")));
これはちょうど時間がなくなり、私は時間の例外を得る。