gpt4 book ai didi

c# - 让 Watin session 保持事件状态

转载 作者:太空宇宙 更新时间:2023-11-03 10:55:48 24 4
gpt4 key购买 nike

我正在尝试使用 Watin 登录一个网站,我想保留 session ,这样我就不会每次都登录。

但是,每次我调用 LogIn 时,行 if (browser.ContainsText(isLoggedInClass)) 都找不到我可以在打开的浏览器中看到的内容。

我添加了行 string checkHtmltoSeeIfClassExists = browser.Body.Parent.OuterHtml; 以物理检查字符串是否包含在 html 中。

我有点卡住了,因为 Watin 似乎没有坚持 session ?有没有人知道出了什么问题?

我目前的代码如下

using WatiN.Core;

namespace ProjectXYZ
{
class Navigate
{
private IE browser;

public void LogIn()
{
const string isLoggedInClass = "gwt-Hyperlink optionLink optionLink_myAccount";
if (browser == null)
browser = new IE("https://www.somewebsite.com");

string checkHtmltoSeeIfClassExists = browser.Body.Parent.OuterHtml;

if (browser.ContainsText(isLoggedInClass))
{
string test = "class found!";
}
else
{
browser.TextField(Find.ByName("username")).Value = xx.un;
browser.TextField(Find.ByName("userpass")).Value = xx.pw;
browser.Button(Find.ByTitle("Login")).Click();
}

}

}

}

最佳答案

你想要的机制是 AttachTo<>函数内置于 WatiN 框架中。因为 WatiN 只支持 single-threaded apartment state ,您必须手动管理您的 session 。

上面的链接有一个使用“AttachTo<>”的代码示例,但为了完整起见,我还在下面提供了一个。

var IE = IE.AttachTo<IE>(Find.ByUrl(someURLHere));

关于c# - 让 Watin session 保持事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19568046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com