简体   繁体   中英

Returned textbox value is empty

Sorry I'm still learning C#, but here's my code and I need help. Basically here's how it is:

The first part of my code went to a settings window where the textbox displays "0%" and my code enters a value of 10 to it.

public void SetDefaultAmount(int amt)
{
 Settings.EnterAmt(amt);
}

public void EnterAmt(int amt)
{
 string amount = amt.ToString();
 Settings.TextBox.Text = amt;
}

So now in setting window, the textbox displays "10%".

My next code goes to a User window where it displays the same textbox and the default value, so the textbox displays "10%" correctly.

I need a code that grabs the textbox value in the Users page, and compare it with the value from the settings page to check if they match. But when i run my code, it gives me the error of "Expected: 10, But was: "string.Empty". How can I fix this? And any better way of streamlining my code? thanks!

This is what my 2nd code is currently, that fails:

**Check if value is 10 (amt = 10)

public void CheckValue(int amt)
{
 string amount = amt.ToString();
 string actualval = UserPage.GetActualVal();
 Assert.AreEqual(amount, actualval, "value did not match");
}

public string GetActualVal()
{
 return UserPage.Textbox.Text;
}

It looks like you're comparing amt, an integer, to actualval, a string. Try Assert.AreEqual(amount, actualval).

After another hour of checking my code, it actually works. the problem turned out to be the automation id of the textbox in the Users page, which was changed without my knowledge so i corrected it already. Thanks for checking and i'd just probably try streamline my code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM