[英]Unable to click button using NHtmlUnit
I have a unit test which simulates a login on Uber. 我有一个单元测试,可以模拟在Uber上的登录。 The goal is to acquire a token that isn't otherwise accessible without an interactive login.
目标是获取令牌,如果没有交互式登录,令牌将无法访问。 I've had this working in the passed but it appears the Uber login experience has changed and now I'm having issues getting NHtmlUnit to successfully submit the login button.
我已经通过了这个工作,但是看来Uber登录体验已经改变,现在我在让NHtmlUnit成功提交登录按钮时遇到了问题。
Here's my latest attempt: https://github.com/wadewegner/uber-sdk-for-net/blob/42fd845fe43e11e3153b07d830ed40e3577b1ed3/src/UberSDKForNet.FunctionalTests/Tests.cs#L100 这是我最近的尝试: https : //github.com/wadewegner/uber-sdk-for-net/blob/42fd845fe43e11e3153b07d830ed40e3577b1ed3/src/UberSDKForNet.FunctionalTests/Tests.cs#L100
Here's the key area: 这是关键区域:
var loginFormButtons = loginForm.GetElementsByTagName("button");
Assert.IsNotNull(loginFormButtons);
var loginButton = (HtmlButton)loginFormButtons.First();
Assert.IsNotNull(loginButton);
var loginButtonText = loginButton.AsText();
StringAssert.Contains("sign in", loginButtonText.toLowerCase());
loginButton.SetAttribute("type", "submit");
loginForm.AppendChild(loginButton);
var consentPage = (HtmlPage)loginButton.Click();
Assert.IsNotNull(consentPage);
I know the code is verbose, but unit testing NHtmlUnit is a nightmare. 我知道代码很冗长,但是对NHtmlUnit进行单元测试是一场噩梦。 I've also tried a ton of different permutations, but they pretty much all end up with a
HtmlButton
. 我还尝试了很多不同的排列,但是它们几乎都以
HtmlButton
结尾。
Everything works great until https://github.com/wadewegner/uber-sdk-for-net/blob/42fd845fe43e11e3153b07d830ed40e3577b1ed3/src/UberSDKForNet.FunctionalTests/Tests.cs#L174 . 一切正常,直到https://github.com/wadewegner/uber-sdk-for-net/blob/42fd845fe43e11e3153b07d830ed40e3577b1ed3/src/UberSDKForNet.FunctionalTests/Tests.cs#L174 。 What I'd expect is for this to take me to the consent page where I'd either allow or deny the Uber app access to my information.
我希望这能带我进入同意页面,在该页面上我将允许或拒绝Uber应用访问我的信息。 However, it appears to simply reload the original page and
consentPage
appears to simply be the same as loginPage
. 但是,它似乎只是重新加载了原始页面,并且
consentPage
页面似乎与loginPage
。
Any NHtmlUnit experts who might have some ideas? 任何NHtmlUnit专家可能有一些想法?
The only thing I'll also point out is that in the past I was able to successfully use HtmlSubmitInput
instead of HtmlButton
but this appears to be one of the changes made by Uber. 我还要指出的唯一一件事是,过去我能够成功使用
HtmlSubmitInput
而不是HtmlButton
但这似乎是Uber所做的更改之一。 Perhaps this is part of the problem? 也许这是问题的一部分?
Well, it's not perfect, but it appears setting the WebClient
to FIREFOX_17
instead of CHROME
solved it. 好吧,这并不完美,但是将
WebClient
设置为FIREFOX_17
不是由CHROME
解决的。
var webClient = new WebClient(BrowserVersion.FIREFOX_17);
See here: https://github.com/wadewegner/uber-sdk-for-net/blob/ceb1cdf80cebb31608744c050b649ddd6a75fb7a/src/UberSDKForNet.FunctionalTests/Tests.cs#L107 参见此处: https : //github.com/wadewegner/uber-sdk-for-net/blob/ceb1cdf80cebb31608744c050b649ddd6a75fb7a/src/UberSDKForNet.FunctionalTests/Tests.cs#L107
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.