Bug or just bad code?

Maddis

Новичок
Регистрация
22.10.2018
Сообщения
27
Благодарностей
3
Баллы
3
I keep getting an error
System.FormatException: Input string was not in a correct format..
I am checking if an element exists based on it's attribute value. If count is 0, I get thrown this error:

Here is my code:

C#:
HtmlElementCollection results = parent.FindChildrenByAttribute("span","innerhtml","chickens","text");
      
if (results.Count == 0)
          
{
       project.SendInfoToLog("Chicken found");
}

else
          
{
       project.SendInfoToLog("Chicken not found");
}

Is this a bug with Zenno, or is there a better way to determine if a child exists when i specify the parent element and expected child attribute value?

Thanks,
Maddis
 

doc

Client
Регистрация
30.03.2012
Сообщения
8 684
Благодарностей
4 641
Баллы
113
I keep getting an error

I am checking if an element exists based on it's attribute value. If count is 0, I get thrown this error:

Here is my code:

C#:
HtmlElementCollection results = parent.FindChildrenByAttribute("span","innerhtml","chickens","text");
     
if (results.Count == 0)
         
{
       project.SendInfoToLog("Chicken found");
}

else
         
{
       project.SendInfoToLog("Chicken not found");
}

Is this a bug with Zenno, or is there a better way to determine if a child exists when i specify the parent element and expected child attribute value?

Thanks,
Maddis
C#:
HtmlElementCollection results = parent.FindChildrenByAttribute("span","innerhtml","chickens","text");
     
if (results == null || results.Count == 0)
         
{
       project.SendInfoToLog("Chicken found");
}

else
         
{
       project.SendInfoToLog("Chicken not found");
}
 
  • Спасибо
Реакции: Maddis

Maddis

Новичок
Регистрация
22.10.2018
Сообщения
27
Благодарностей
3
Баллы
3
C#:
HtmlElementCollection results = parent.FindChildrenByAttribute("span","innerhtml","chickens","text");
    
if (results == null || results.Count == 0)
        
{
       project.SendInfoToLog("Chicken found");
}

else
        
{
       project.SendInfoToLog("Chicken not found");
}
Thank you for your reply. I have tried to use the same logic to check if an element exists, but I get "Faulty Operation xxx of the action group id:"

C#:
Tab tab = instance.ActiveTab;

string criteria = "My Element";
int rCount = 0;
    
HtmlElementCollection results = null;

Top:;

results = tab.FindElementsByAttribute("span","innertext", @criteria,"text");
rCount = results.Count;

if (rCount == 0)
        
{
       goto Top;
}

// Element Found

project.SendInfoToLog("Element found");
 

Maddis

Новичок
Регистрация
22.10.2018
Сообщения
27
Благодарностей
3
Баллы
3
I have also tried this:
C#:
Tab tab = instance.ActiveTab;
string criteria = "My Element";
int retCount = 0;

Top:;

HtmlElementCollection results = tab.FindElementsByAttribute("span","innertext", @criteria,"text");

if (results == null)   
{
    retCount = 0;
}
else
{
    retCount = results.Count;   
}

if (retCount == 0) {goto Top;}
The thing is, after the error occurs (once the element has been loaded/found in the current instance),if I then execute the snippet again, the code executes fine, and doesn't give me an error.
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)