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:
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:
I am greatly confused about this ,I donot know what to do .
CAN anyone help me ? I am very thankful