没有这样的元素:无法使用 Selenium 和 C# 定位元素:{“method”:“css 选择器”,“selector”:“#Password”}
我编写了一个简单的登录测试,
namespace Seleniumtest.Customer
{
[TestFixture]
class LoginTest :TestBase
{
[Test]
public void LoginWithPhoneNumber()
{
webDriver.Navigate().GoToUrl("https://test123.ifc.ir/login");
webDriver.FindElement(By.Id("EmailOrPhoneNumber")).SendKeys("09108599423");
webDriver.FindElement(By.ClassName("buttons")).Click();
var input = webDriver.FindElement(By.Id("Password"));
Assert.That(input.Displayed, Is.True);
}
}
}
该程序将单击登录并登录并查找部分视图输入密码,但它只是将用户名中的值插入并单击提交,但从未找到密码。
I wrote a simple test for login
namespace Seleniumtest.Customer
{
[TestFixture]
class LoginTest :TestBase
{
[Test]
public void LoginWithPhoneNumber()
{
webDriver.Navigate().GoToUrl("https://test123.ifc.ir/login");
webDriver.FindElement(By.Id("EmailOrPhoneNumber")).SendKeys("09108599423");
webDriver.FindElement(By.ClassName("buttons")).Click();
var input = webDriver.FindElement(By.Id("Password"));
Assert.That(input.Displayed, Is.True);
}
}
}
This program will click login and have login and find partial view input password but its just instert the value in username and click the submit but never find password.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是,在第一页上您有
用户名
和可点击
按钮,一旦您单击该按钮,它会将您重定向到一个新页面,您可以在其中提供密码。但是,这个新页面未正确呈现,这就是您
在 C#-Selenium 绑定中,您可以使用
显式等待
的原因,如下所示:现在输入是一个 Web 元素,您可以输入使用
SendKeys
方法获取密码。参考链接
The issue is that on page one you have
username
andclickable
button, and once you click on the button it will redirect you to a new page where you can provide the password.However, this new page is not rendered properly and that's the reason you are getting
In C#-Selenium bindings, you can use the
explicit wait
like below:and now the input is a web element, you can input the password with
SendKeys
method.Reference link
通过
get()
调用URL后,填写EmailOrPhoneNumber字段并单击提交按钮密码字段需要一些时间才能可见并且可交互。解决方案
在这些情况下,要在所需元素上调用
Click()
,您必须引入 WebDriverWait 对于 ElementToBeClickable ,您可以使用以下定位器策略:Id:
CssSelector:
XPath:
参考资料
您可以在以下位置找到一些相关的详细讨论:
Once you invoke the url through
get()
, fillup the EmailOrPhoneNumber field and click on the Submit button it would need a little while for the Password field to be visible and interactable.Solution
In these cases to invoke
Click()
on the desired element you have to induce WebDriverWait for the ElementToBeClickable and you can use either of the following locator strategies:Id:
CssSelector:
XPath:
References
You can find a couple of relevant detailed discussions in: