当我使用 C++ 中的 C# dll 来使用 Selenium 时,存在异常处理问题
when i use C# dll from C++ for using Selenium, there is exception handling problem
它在 c# 代码上运行良好。但是,如果我使用 c# dll 在 c++ 上执行,则会发生异常处理错误。
首先,我将向您展示我的代码。
- C# 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace ManagedLibrary1
{
public interface LoginClass
{
void LogIn(string id, string pw, int t, int num);
void LogOut();
}
public class Class1 : LoginClass
{
IWebDriver driver = new ChromeDriver();
IWebElement a;
Boolean b;
public void LogIn(string id, string pw, int t, int num)
{
if (num == 0)
{
driver.Navigate().GoToUrl("this is url address");
}
else
{
driver.Url = "this is url address2";
}
Thread.Sleep(50);
if (t == 0)
{
a = driver.FindElement(By.XPath("this is Xpath"));
b = a.Displayed;
if (b == true)
{
a.Click();
}
}
driver.FindElement(By.XPath("this is xpath2")).SendKeys(id);
Thread.Sleep(50);
driver.FindElement(By.XPath("this is xpath3"]")).SendKeys(pw);
Thread.Sleep(50);
driver.FindElement(By.XPath("this is xpath4")).Click();
Thread.Sleep(5000);
a = driver.FindElement(By.XPath("this is xpath5"));
if (b == true)
{
driver.Url = "this is url address 3";
}
driver.Manage().Window.Maximize();
driver.FindElement(By.ClassName("this is classname")).Click();
}
public void LogOut()
{
a = driver.FindElement(By.XPath("this is xpath6"));
b = a.Displayed;
if (b == true)
{
a.Click();
}
}
}
}
- >C++代码
#include <windows.h>
#include "tchar.h"
#import "C:UsersmeDesktopProject FolderClassLibrary4ClassLibrary4binDebugClassLibrary4.tlb" raw_interface_only
using namespace ClassLibrary4;
int main()
{
HRESULT hr = CoInitialize(NULL);
LoginClassPtr pICalc(__uuidof(Class1));
pICalc->LogIn("id","password",1,0);
CoUninitialize();
return 0;
}
调试C++代码时,在此处生成错误
LoginClassPtr pICalc(__uuidof(Class1));
如果接收dll函数的过程是错误的,我尝试将C#的函数部分更改为非常简单的函数,该函数计算两个整数的总和,并且运行良好,没有错误。
只有这一个问题让我两天没有前进。我需要你的帮助。
我正在处理类似的问题,我的 c# dll 是用强名称签名的 dll。我使用的Selenium Webdriver nuget包没有一个强名称。显然,强命名的 dll 无法加载另一个没有强名称的 dll。我卸载了硒网络驱动程序包并安装了硒网络驱动程序.strongname,这对我有用。
相关文章:
- C++模板来检查友元函数的存在
- 处理多个异常集合的C++方法
- 我在c++代码中生成了一个运行时#3异常
- 孤立代码块在结构中引发异常
- C++中的赋值发生,尽管右侧出现异常
- 当我使用 C++ 中的 C# dll 来使用 Selenium 时,存在异常处理问题
- 存在内存访问异常,但我不确定我的代码中出了什么问题
- 尝试使用 wxWidgets 从 zip 打开不存在的文件时无法捕获的异常
- 是否存在与将数据流式传输到 c++ 异常类相关的任何危险
- 在存在异常的情况下使用for_each? std::exception_list
- 为什么在打印Un_ordered Map and Map(字典)的密钥和值时存在异常
- STL中使用引用计数的数据结构存在哪些行为异常
- 异常处理 - 使用另一个文件名写入文件(如果该文件与原始文件名一起存在)
- 递归函数存在out_of_range异常
- 如果文件在构造函数中不存在,则抛出异常,并在 main() 中创建对象时尝试/捕获它,如果好 - 开始使用该对象
- 打开包含不存在文件的文件流后不会引发异常
- 异常错误:在")"令牌之前应存在非限定 id
- 在for循环内部使用时,是否存在任何异常甚至极端的情况,即后增量实际上比预增量更好
- 访问内存中不存在的数组索引的正确异常类型?
- 如果异常保存在std::exception_ptr中,那么在catch语句之外使用异常是否安全?