Hi,
I use a function in one C# block like
which returns a string value. I call it from another c# block like this
And it does return a string, as I can output this value to log. However, when I try to use the variable is_seller_on_page in IF-clause, I get an error "Perform the CSharp OwnCode object reference not set to an instance of an object."
Is it a bug or something with my code?
I used
to check if I receive the empty string.
now I rewrote a bit
which works,
but I am curious, why I have an issue with object if the function returns a string?
Another question is it possible to get a row number when this kind of error happens? Because to find out it, I need to copy/paste code with output to log after every action in code, which is inconvenient.
Thanks.
I use a function in one C# block like
Код:
/* Function to find a selller */
project.Context["CheckSeller"] = (Func<string>)(() => {
//get brand name and counter from project
ILocalVariable brand_name = project.Variables["brand_name"];
int counter = int.Parse(project.Variables["counter"].Value);
// All Departments. Check if brand is a seller in All Departments. If name is similiar, than it stored in Brands table F
string empty_string = "";
var table_brands = project.Tables["brands"];
string seller1 = "";
string to_return = ""; //return value
string pattern = @brand_name.Value; //for regex
string input = ""; //regex
//ILocalVariable brand_is_seller = project.Variables["brand_is_seller"];
HtmlElement seller1_xpath_result = instance.ActiveTab.FindElementByXPath("//h4[contains(., 'Seller')]/following-sibling::ul[1]/div/li[1]",0);
seller1 = seller1_xpath_result.GetAttribute("innerText");
// if sellers' checkboxes appear in all Departmens after selecting Brand's checkbox, try to find sellere name
if (!seller1_xpath_result.IsVoid){
input = seller1;
//compare brand name to alternative brand name
Match m = Regex.Match(input, pattern, RegexOptions.IgnoreCase);
if(m.Value !=""){
//project.SendWarningToLog(m.Value, "The brand has the seller with name: ", true);
//table_brands.SetCell("F", counter, m.Value);
to_return = m.Value;
} else {to_return = "";}
}
return to_return;
//return input;
});//end function CheckSeller
Код:
string is_seller_on_page = project.Context["CheckSeller"]();//function is in another block
Is it a bug or something with my code?
I used
Код:
if (is_seller_on_page == "" ){
now I rewrote a bit
Код:
get_is_seller_on_page = is_seller_on_page.CompareTo("");
but I am curious, why I have an issue with object if the function returns a string?
Another question is it possible to get a row number when this kind of error happens? Because to find out it, I need to copy/paste code with output to log after every action in code, which is inconvenient.
Thanks.