[Solved] c# selenium if else check [closed]


This is what you are asking for

if (rows == null)
{
     continue;
}
else
{
     rows.ElementAt(0).Click();
     break;
} 

However it’d be better code practice and more efficient to use a while loop implementation instead;

    IReadOnlyCollection<IWebElement> rows = null;

    bool rowsFound = false;
    while (!rowsFound)
    {
         rows = driveri.FindElements(By.XPath("//*[@id=\"app\"]/div/span[3]/div/div/div/div/div/div/div[2]/div"));

         if(rows!=null)
         {
             rowsFound = true;
         }
    } 

 rows.ElementAt(0).Click();

On an unrelated topic, it’s also bad practice to be using Thread.Sleep(), unless absolutely necessary. Most, if not all the time you will want to use WebDriverWait implementation. You can find out more about that here: https://seleniumhq.github.io/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Support_UI_WebDriverWait.htm

solved c# selenium if else check [closed]