Click here to Skip to main content
16,022,309 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi guys this is my code and Try and Catch part is not working on the program can anyone help?


   Task<bool?> check = Task<bool?>.Run(() => check_());
                //set variable to the returned boolean of the check function.
                bool? working = await check;

 else if (working == false)
                {


                    //      driver.Manage().Cookies.DeleteAllCookies();
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine(user[0] + " " + user[1] + "is not working");
                    Console.ResetColor();
                    Console.WriteLine("false");

//this part is not working
                    try
                    {
                        driver.FindElement(By.XPath("//*//*[@id=\"ember43\"]")).SendKeys(OpenQA.Selenium.Keys.Enter);
                        listBox3.Items.Add(item);


                    }
                    catch (NoSuchElementException)
                    {
                        Console.ForegroundColor = ConsoleColor.Blue;
                        
                        driver.Navigate().Refresh();

                    } 


What I have tried:

can anyone help please thanks......................................
Posted
Updated 16-Dec-21 6:39am
v2
Comments
[no name] 17-Dec-21 4:29am    
How do you know it is not working?

1 solution

"It's not working" is one of the most useless problem descriptions we get: it tells us absolutely nothing about the problem. We don't know if you get an error message, or the wrong data, or even that that code compiles successfully!
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So tell us what happens when you run that code, what you expected to happen, how you checked what happened. Help us to help you!

And to be honest, even with the error message your code studiously ignores, we can't help because we have no access to the document that presumably is throwing the exception.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Start by adding a variable to the catch exception so you can inspect it and find out why an exception occurred (assuming it does) and then put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900