LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C# vs LabVIEW when calling .net dll

Solved!
Go to solution

Today I made a .net dll, this dll is aimed to call Chroma by Selenium.

my C# code for the dll is as below:

 

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

 

namespace web_functions
{
public class AppException : Exception
{
public AppException(String message) : base(message)
{ }

public AppException(String message, Exception inner) : base(message, inner) { }
}

public class web_functions1
{
public IWebDriver driver1 { get; set; }
public int test1 { get; set; }
public IWebDriver OpenWeb()
{
ChromeOptions options = new ChromeOptions();

IWebDriver driver = new ChromeDriver(options);
this.driver1 = driver;
this.test1 = 12;

return driver;
}
public int test(int a, int b)
{ return a + b; }

public bool GoToUrl(IWebDriver driver, string Url)
{
driver.Navigate().GoToUrl(Url);
return true;
}
public IWebElement FindElementById(IWebDriver driver, string id,out string err)
{
IWebElement element_by_id = null;

try
{
element_by_id = driver.FindElement(By.Id(id));
err = "ok";
}
catch (AppException e)
{
Console.WriteLine("In catch block of Main method.");
Console.WriteLine("Caught: {0}", e.InnerException);
err = e.InnerException.ToString();


}

return element_by_id;
}
public IWebElement FindElementByxpath(IWebDriver driver, string xpath)
{
IWebElement element_by_xpath = driver.FindElement(By.XPath(xpath));
return element_by_xpath;
}
public int FindElementsRowCountByxpath(IWebDriver driver, string xpath)
{
int size = driver.FindElements(By.XPath(xpath)).Count;
return size;
}
public bool SetElementValue(IWebElement element, string key)
{
element.SendKeys(key);
return true;
}
public bool ClickElement(IWebElement element)
{
element.Click();
return true;
}
public string GetElementAttribute(IWebElement element, string AttributeName)
{
string a33 =element.GetAttribute(AttributeName);
return a33;
}
}
}

 

and then I created a C# main cs file,to call that dll.see as below:

 

using System;
using System.IO;
using web_functions;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace ota_dll_caller_test
{
class caller
{
static void Main(string[] args)
{

//string a0 = o1.GetAdbDeviceLists();
//Console.WriteLine(a0);
//string a1 = o1.and_get_screenshot("D:\\123");
//Console.WriteLine(a1);
//string a2 = o1.a002get_pic("D:\\124");

string filePath = @"D:\pic_disting\input.txt"; // 替换为你的文件路径
string content;
string a0 ;
try
{
web_functions1 c1 = new web_functions1();

IWebDriver driver = c1.OpenWeb();
Console.WriteLine("Convert.ToUInt32(driver)");
Console.WriteLine("cc");
Console.WriteLine(c1.test1);
string cc;
bool a1 = c1.GoToUrl(driver, "https://xxxxxx");
IWebElement a2 = c1.FindElementById(driver, "username",out cc);
Console.WriteLine(cc);
bool a3 = c1.SetElementValue(a2, "xxx");
IWebElement a4 = c1.FindElementById(driver, "password", out cc);
bool a5 = c1.SetElementValue(a4, "xxx");
IWebElement a6 = c1.FindElementById(driver, "login-submit", out cc);
c1.ClickElement(a6);
bool a7 = c1.GoToUrl(driver, "https://xxxxxx");
IWebElement a8 = c1.FindElementById(driver, "attach_files_link", out cc);
c1.ClickElement(a8);
int a9 = c1.FindElementsRowCountByxpath(driver, "//*[@id='content']/div[3]/table/tbody/tr");
Console.WriteLine(a9);
}
catch (IOException e)
{
Console.WriteLine("An IO exception has been thrown!");
Console.WriteLine(e.ToString());
}


Console.ReadKey();
}


}
}

 

 

it works well , cmd windows appeared as below:

333.png

 

but after I copied the dll(and all other files in that debug folder) to labview path ,and call the dll by .net node,things become worse,see as below:

 

44.png

I am greatly confused about this ,I donot know what to do .

 

CAN anyone help me ? I am very thankful

0 Kudos
Message 1 of 4
(201 Views)
Solution
Accepted by topic author alii001

Since it looks like you define OpenWeb as a function, then call it via LabVIEW, it's a problem from that section of code, and I only see one place in it that could make an error, and that's this:

 

IWebDriver driver = new ChromeDriver(options)

 

So I would speculate that calling "new ChromeDriver()" generates this message.

 

Focusing on this part of the message:

Kyle97330_0-1728578974547.png

makes me believe that it's searching for "selenium-manager.exe" at a certain path and not finding it.  Looking at the path and seeing that the backslashes change to forward slashes partway through, I would speculate that it's running some sort of "get current path" function, followed by appending more directories to the path and then looking for the EXE at that location.  But something about the combination of you making this into your own DLL and then calling it from LabVIEW makes that "get current path" function report a location that is not relative to the EXE it's looking for.

 

I don't know how to fix it though.  I would look into seeing if you can get more details on new ChromeDriver() and see if any of the options it accepts can redefine the path, or if you can find out what relative path it's using and adapt to it somehow.

Message 2 of 4
(163 Views)

Just to be sure, I'd also run LabVIEW as an administrator. At least until things work.

0 Kudos
Message 3 of 4
(114 Views)

Thankyou,I soved the problem by your instruction

0 Kudos
Message 4 of 4
(112 Views)