如果显示密码样式,如何使用Selenium Webdriver输入密码:无 [英] How to enter password using Selenium webdriver if the password style is display:none

查看:70
本文介绍了如果显示密码样式,如何使用Selenium Webdriver输入密码:无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有登录名和密码(betmarathon [d.o.t] com)的页面.我想使用Selenium Webdriver登录该站点.Selenium正确输入登录名,但是输入密码有问题.我收到元素不可见"异常.

I have a page with login and password (betmarathon[d.o.t]com). I want to login to the site using selenium webdriver. Selenium enters the login correctly, but i have problems with entering password. I get "Element not visible" exception.

我的硒代码如下:

driver.findElement(By.id("auth_login")).sendKeys("MY-USERNAME");
driver.findElement(By.id("auth_login_password")).sendKeys("MY-PASSWORD");

页面的HTML代码如下:

Html code of the page looks like this:

<div class="user">
<input id="auth_login" class="empty" type="text" maxlength="40" rel="Login:" name="login" tabindex="1">
</div>
<div class="pass">
<input id="auth_login_password" type="password" regex="^.{6,}$" maxlength="100" rel="Password:" name="login_password" tabindex="2" style="display: none;">
<input class="undefined empty" type="text" value="Password:" tabindex="2" style="display: inline;">
</div>

您会看到有2个密码输入,第一个不可见,第二个可见.我应该在第一个输入中输入密码.手动单击该框后,html代码将更改,并且密码的第一个输入变为可见(display:inline),第二个更改为display:none.但是我该如何使用Selenium Webdriver?

You can see that there are 2 inputs for password, the first one is not visible and the second is visible. I should enter the password in the first input. After I click on the box manually, the html code changes and the first input for password becomes visible (display:inline) and the second changes to display:none. But how can I do it with selenium webdriver?

非常感谢.

推荐答案

driver.ExecuteScript(string.Format("document.getElementById('cred-password-inputtext').value='{0}';",password));

这为我解决了问题

这篇关于如果显示密码样式,如何使用Selenium Webdriver输入密码:无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆