Mikail hP
Mikail hP

Reputation: 39

How to refresh WebElement in Selenium Webdriver without reload page?

I need to refresh WebElement in Selenium Webdriver without reload page.
When i use a while, the text of the page element is constantly updated because it is a chat, but the loop carries only the same text.

while (driver.FindElements(By.ClassName("chat")).Count() > 0)
            {
                {
                    var element = driver.FindElement(By.ClassName("_chat")).Text;
                    Console.WriteLine(element);
                }
            }

I am using a C# project.
Thanks!

Upvotes: 1

Views: 1830

Answers (2)

supputuri
supputuri

Reputation: 14135

Try this.

for (int i = 0; i < 5; i++) {
           while (driver.FindElements(By.ClassName("chat")).Count() > 0)
            {
                {
                    var element = driver.FindElement(By.ClassName("_chat")).Text;
                    Console.WriteLine(element);
                }
            }
}

Upvotes: 0

Ruyut
Ruyut

Reputation: 181

Sorry i use java If you get element outdated errors you can use it

WebDriverWait wait = new WebDriverWait(driver, 5);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("_chat")));

Instead of

wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.name("_chat"))));

not use driver.findElement

Upvotes: 0

Related Questions