gpt4 book ai didi

c# - 如何将文本插入文本框 selenium c#

转载 作者:行者123 更新时间:2023-11-30 15:53:46 28 4
gpt4 key购买 nike

    <div class="input-container">

<div class="form-group">
<div class="labelContainer">
<<p>Current Password<span>*</span></p>
</div>
<label for="currentPassword" class="sr-only">Current Password</label>
<input type="password" id="currentPassword" name="currentPassword" class="form-control" placeholder="Current Password" required="">
<i class="fa fa-lock icon-style" aria-hidden="true"></i>
</div>

<div class="form-group">
<div class="labelContainer">
<<p>Enter New Password<span>*</span></p>
</div>
<label for="newPassword" class="sr-only">New Password</label>
<input type="password" id="newPassword" name="newPassword" class="form-control" placeholder="New Password" required="">
<i class="fa fa-lock icon-style" aria-hidden="true"></i>
</div>

<div class="form-group">
<div class="labelContainer">
<<p>Confirm New Password<span>*</span></p>
</div>
<label for="confirmPassword" class="sr-only">Confirm New Password</label>
<input type="password" id="confirmPassowrd" name="confirmPassowrd" class="form-control" placeholder="Confirm Password" required="">
<i class="fa fa-lock icon-style" aria-hidden="true"></i>
</div>

以上是 html 代码,我想将当前密码插入当前密码文本字段。我尝试了下面的两种方法,但它说元素不可见是行不通的。

(code 1 )driver.FindElement(By.Id("currentPassword")).SendKeys("testabc");
(code 2 )IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("document.getElementById('currentPassword').value='testabc';");

尝试测试 newPassword 文本字段而不是 currentPassword 文本字段,它工作正常。只有 currentPassword 和 confirmPassword 文本字段的错误消息元素不可见。

有谁知道是什么问题吗?

最佳答案

你可以试试这个,

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible(By.Id("currentPassword"))).SendKeys("testabc");

关于c# - 如何将文本插入文本框 selenium c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51853077/

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