0

How can I access the variable code_works when it gets updated from the try/catch? I have Lenovo.code_works placed on a button event, but it never updates, it stays at the initialized string "Waiting to Start Proccess", when I try to call the variable from the try/catch it says it isn't found. How would I go about fixing this?

public class Lenovo
{
    //Some Variables
    public static bool isTrue = true;
    public static string idWarranty;
    public static string code_works = "Waiting to Start Process";
    
    public static void LenovoMonitor()
    {
        


        while (isTrue == true)
        {


            idWarranty = "u93302";

            
            Driver.Navigate().GoToUrl("https://pcsupport.lenovo.com/us/en/products/monitors-and-projectors/lcd-monitors/lenovo-y44w-10/65ea/65earac1us/" + idWarranty + "/warranty");



            //Find Element
            try
            {
                IWebElement inputText = Driver.FindElement(By.XPath("/html/body/div[2]/section[2]/div[2]/div/div[2]/div/div[1]/div/div/div[2]/ul/li[2]/span"));
                Console.WriteLine(idWarranty + " Works!");
                code_works = idWarranty + " Works!";


            } catch
            {
                Console.WriteLine("Invalid Code // No Warranty");
            }
  • where is the button event?? – Oluwadamilola Adegunwa May 15 '21 at 03:17
  • In the MainWindow class (wpf). The Lenovo class is seperate. ‎‎ ‎‎‎‎‎‎‎‎‎ ‎ Output_Working.Text = Lenovo.code_works; – gemmydawg May 15 '21 at 03:25
  • 1
    Make sure you are binding that string to the text box that is displaying the value of it, this is normally done with `INotifyPropertyChanged`. Check out [this](https://stackoverflow.com/questions/1725554/wpf-simple-textbox-data-binding) it might help you out. – DekuDesu May 15 '21 at 04:10
  • I was using Output_Working_TextChanged, and it seems to change the text, but the problem is in the try/catch area where code_works is getting updated. I can't use a return on it because LenovoMonitor() won't accept string as a property, it only accepts void – gemmydawg May 15 '21 at 04:37
  • What does "accepts void" mean? Void is something(nothing, actually) that is *returned*, not *accepted* – Caius Jard May 15 '21 at 05:10
  • Accepts void as in any other property it will not accept. I think it's due to selenium's webdriver I'm not sure though. I would set a return and string, but that doesn't work... – gemmydawg May 15 '21 at 05:22
  • when is the value of isTrue changed? I see a possible infinite loop. – Akshay G May 15 '21 at 07:47
  • it is true when the 'start' button is pressed on the form, when 'stop' button is pressed it changes it to false. i didn't include the rest of the code where it includes that – gemmydawg May 15 '21 at 09:44

0 Answers0