I have a project with Selenium WebDriver and I need to catch an event when a certain web element shows up in the web page. It is like a button click from user in a windows forms app while the programm to be doing its stuff, but it program reacts to pressing the button.
And how to implement this logic in the test project?
// here some code
[Test]
public void WebDriverEventListeners()
{
EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(webDriver);
eventFiringWebDriver.FindElementCompleted += EventFiringWebDriver_FindElementCompleted;
eventFiringWebDriver.FindElement(MainMenuLocators._signInButton);
}
private void EventFiringWebDriver_FindElementCompleted(object? sender, FindElementEventArgs e)
{
Console.WriteLine("Found ya!");
}
// here some code
I’ve created only that: when the web element is found an event is triggered. And it works.
But how to catch an event without this code? How to create a listener which will listen to the web page and wait until the certain web element shows up? I need this to close some garbage forms like cookie files buttons or tips on the site. It is not known when such forms may appear.
Генри Томасино is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.