Reputation: 2438
I have label with text changed from MQL
to SQL
value.
<label for="stage_label" id="Stage_label"><div class="ms-crm-div-NotVisible">Stage SQL</div>SQL<div class="ms-crm-Inline-GradientMask"></div></label>
I need to wait until label contains 'SQL' value.
If I use Selenium native wait method my test fails in 30 seconds with TimedoutException
var wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(30000));
wait.Until(ExpectedConditions.TextToBePresentInElement(driver.FindElement(
By.Id("Stage_label")), "SQL"));
At the same time if I try to debug and check element text it successfully returns SQL after some time of waiting
for (int i = 0; i < 5; i++)
{
Console.WriteLine(driver.FindElement(
By.Id("Stage_label")).Text);
Thread.Sleep(100);
}
MQL MQL MQL SQL SQL
Why Selenium method doesn't work in this case?
Upvotes: 2
Views: 777
Reputation: 433
Okay since you confirmed the containing element is being destroyed and recreated I can better help. You should be able to just use the "TextToBePresentInElementLocated" instead. This takes a By object instead of the element itself.
var wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(30000));
wait.Until(ExpectedConditions.TextToBePresentInElementLocated(By.Id("Stage_label"), "SQL"));
Upvotes: 1
Reputation: 12930
how about this
var wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(30000));
var element = driver.FindElement(By.Id("Stage_label"))
wait.Until(ExpectedConditions.TextToBePresentInElement(element, "SQL"));
Upvotes: 0
Reputation: 2438
As @CodingKuma suggested the form is refreshing during value update and element disappears from DOM. So it required to wait until element is stalled and then wait for element to appear.
Upvotes: 0