0

The code that worked for me well. I get the quantity of messages first and then remove it.

    public static void RemoveMSGs()
    {
        // Remove messages from DOM using JS
        int MessagesOnThePage = Program.ChromeDriver.FindElementsByClassName("GLS-JUXDKAD").Count;
        Console.WriteLine("Total messages: " + MessagesOnThePage);

        while (MessagesOnThePage != 0)
        {
            MessagesOnThePage--;
            {
                try
                {
                    Program.js.ExecuteScript("var ele = document.querySelector('.GLS-JUXDKAD'); ele.parentNode.removeChild(ele); "); // This code removes the whole message
                    Console.WriteLine("JS execution command: remove message on the page. Total messages on the page: " + MessagesOnThePage);
                }
                catch
                {
                    Console.WriteLine("JS error. Can't remove message on the page. There is no more messages. Total messages: " + MessagesOnThePage);
                }
            }
        }
    }

1 Answer 1

2

Just wrap the following lines in your selenium code

var ele = document.querySelector('GLS-JUXDFAD');
ele.parentNode.removeChild( ele );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.