简体   繁体   English

使用NHtmlUnit无法单击按钮

[英]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.

相关问题 如何使用gapi从应用程序注销而无需单击按钮 - How to signOut from an app using gapi without needing to click on a button 如何在节点环境中模拟浏览器按钮单击? - How do I simulate a browser button click in a node environment? 无法使用xoauth将电子邮件发送到Javamail上的gmail - Unable to send email to gmail on javamail using xoauth 如何在我的Android应用程序中注销谷歌用户点击在Java? - How To Logout a Google User in my Android Application on Button Click In Java? 无法使用承载令牌通过 Keycloak 进行身份验证 - Unable to authenticate with Keycloak using Bearer Token 无法使用Google行动中的隐式/授权流程对用户进行授权 - Unable to Authorize users using Implicit / Authorization flow in google actions 无法使用 Postman oAuth2.0 获取 Devops 的授权代码 - Unable to get Authorization code for Devops using Postman oAuth2.0 我无法使用http上的oauth2验证CKAN 2.7.2 - I am Unable to authenticate CKAN 2.7.2 using oauth2 on http 无法使用Android的Asmack库登录到Google Talk - Unable to login to google talk using asmack library for android 无法使用ExpressJS与oauth2orize提供程序保持持久登录 - Unable to keep a peristent login with the oauth2orize provider using ExpressJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM