我正在等待Selenium在等待另一个元素之前切换更改帧.即
var wait = new WebDriverWait(driver, 15);
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Id("frameA"));
var wait2 = new WebDriverWait(driver, 15);
// wait for element within frameA to exist
wait2.Until(ExpectedConditions.ElementExists(By.Id("elementA")));
如果我抛入一个简单的Thread.Sleep(1000);在第二次等待之前它运行正常,但没有它我得到以下错误:
'unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot find context with specified id"}
enter code here
有没有更好的方法等待帧上下文切换完成,然后才能填充该帧中的元素?
解决方法:
您需要考虑以下几点:
切换到框架的代码行看起来很完美,不会引发任何错误:
var wait = new WebDriverWait(driver, 15);
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Id("frameA"));
在下一行中,您已尝试使用ExpectedConditions方法ElementExists.根据API Docs ElementExists
方法定义为:
An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.
在元素可见之前,硒不能与元素相互作用.因此,您需要使用方法ElementIsVisible
如下:
var wait2 = new WebDriverWait(driver, 15);
wait2.Until(ExpectedConditions.ElementIsVisible(By.Id("elementA")));
在这里您可以找到关于Ways to deal with #document under iframe的详细讨论
原文地址:https://codeday.me/bug/20190607/1194876.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。