您需要考虑以下几点:
切换到框架的代码行看起来很完美,不会引发任何错误:
var wait = new WebDriverWait(driver, 15);wait.Until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.Id("frameA"));在下一行中,您尝试了 ExpectedConditions 方法 ElementExists 。根据 API DocsElementExists
方法的定义为:
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")));


