Search for text and compare with a number

0

I want to search for a text and compare it with a number, if it's higher than a number like that, run an if and if it's lower an else

 string sato = driver.FindElement(By.CssSelector(".user_reward_points")).Text;
 if (sato > 1200)
 {
     driver.FindElement(By.CssSelector("#free_points_rewards > .effect2:nth-child(2) .large-3:nth-child(3) > .reward_link_redeem_button_style")).Click();
 }
    
asked by Gabriel Lugo 08.10.2018 в 23:38
source

1 answer

0

You must first convert the string containing sato to a numeric value to be able to compare it as you want

You can use the TryParse method to convert it and handle an error in case it can not be converted

int satoInt;
if (int.TryParse(sato, out sato))
{
    if (sato > 1200)
    {
      driver.FindElement(By.CssSelector("#free_points_rewards > .effect2:nth-child(2) .large-3:nth-child(3) > .reward_link_redeem_button_style")).Click();
    }
    else
    {
        //Haz otra cosa
    }
}
else
{
     //Handler para el error al convertir el campo sato a int
}
    
answered by 09.10.2018 в 01:31