所以我的html看起来像这样:
<section>
<div>
<form>
<div>here is username field</div>
<div>here is password field</div>
<div>
<div>..
<div>..
<iframe>here is checkbox field</iframe>
</div>
</div>
</div>
<div>here is login button</div>
</form>
</div>
<div>resetpassword button</div>
</section>
以及我的硒代码是什么
const iframe = await this.getElementBySelector('#form-login > div:nth-child(3) > div > div > div > iframe');
await getCurrentDriver().switchTo().frame(iframe);
const checkBox = await this.getElementBySelector('#checkbox');
await checkBox.click();
await getCurrentDriver().switchTo().defaultContent();
const loginSubmitButton = await this.getElementBySelector('#login');
await loginSubmitButton.click();
现在问题是甚至在尝试切换到默认内容后,我无法点击登录按钮(这是iframe但在表单内,但是,如果我尝试找到重置密码按钮切换到默认内容后这是形式之外的)它很棒。 有一些与iframe /表格相关的微不足道的东西,我可能会丢失,这使我的登录按钮不被点击..任何领导朋友?
PS:登录按钮在我们切换到目标框架之前被禁用,但是当我们执行switchTo()。defaultContent()时,它认为该按钮仍未启用,在UI上按钮出现即可启用。
答案 0 :(得分:0)
在切换回默认内容之前添加一个等待语句为我解决了这个问题。谢谢@JeffC的答案。