How to refresh WebElement in Selenium Webdriver without reload page?

1,304 views
Skip to first unread message

Matheus Santos

unread,
Mar 14, 2020, 1:26:03 AM3/14/20
to Selenium Users
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!

Matheus Santos

unread,
Mar 14, 2020, 5:44:02 AM3/14/20
to Selenium Users
Any help?

Matheus Santos

unread,
Mar 16, 2020, 6:48:09 AM3/16/20
to Selenium Users
Any help?

Anand Somani

unread,
Mar 16, 2020, 9:43:33 AM3/16/20
to seleniu...@googlegroups.com
FindElement always find element not looking at cache so you should get latest data in element, Could you try to use By.Xpath instead of By.ClassName.

Thanks & Regards,
Anand Somani


On Mon, 16 Mar 2020 at 10:48, Matheus Santos <mathan...@gmail.com> wrote:
Any help?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ab6c7c62-c695-4d93-bac7-b1fe8c59e825%40googlegroups.com.

Matheus Santos

unread,
Mar 18, 2020, 6:58:34 PM3/18/20
to Selenium Users
Thanks, but not resolved...

Adrian

unread,
Mar 18, 2020, 10:00:20 PM3/18/20
to Selenium Users
Hi Matheus,
I am wondering if the element with the classname _chat contains the data you are after?
Is there more than 1 _chat classname element as more text is added?  If this is the case then the code you are using will only find the 1st one.
You might need to do a driver.FindElements() and then loop thru the results.


Cheers,
Adrian.

Scott Babcock

unread,
Mar 18, 2020, 10:55:29 PM3/18/20
to Selenium Users
It's always ill-advised to poll *anything* with no pause of any kind between iterations.

Also, you don't provide any details of the structure you're targeting. You need to be sure that your queries will actually find the elements you intend. It's possible that you're finding hidden elements, which will always return an empty string for the text content. You're searching for all elements on the page to which class "chat" is applied, looping as long as at least one element is found. Within the loop, you're searching for the first element on the page to which class "_chat" is applied.

Examine the structure of the elements on the page. It's possible that you have more than one "_chat" element, or that you're dealing with a page with frames in it, or some other scenario that your simple loop doesn't handle.
Reply all
Reply to author
Forward
0 new messages