如何使用硒元素嵌套C#

How to nest using selenium elements C#

我使用 Selenium 做了很多测试。我很好奇我是否正确嵌套。我不确定是否有更好的方法,如果有我会很高兴听到它。

目前,我在启动时使用 WinApp 驱动程序打开了一个 PowerPoint 会话。然后在嵌套时我执行以下操作。在这里,我找到了一个名为 Linking 的元素。元素树中 Linking 的子元素是 Update 等等。

var linking = session.FindElementByName("Linking");
var update = linking.FindElementByName("Update");// within the linking element there is an update button
update.Click();
session.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
var all =update.FindElementByName("All");// within the update element there is a dropdown menu with an "All" button
session.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
all.Click();

在评论中,您提到代码的问题是 all 除非您进入睡眠状态,否则无法点击。

使用显式等待。类似于:

new WebDriverWait(session, TimeSpan.FromSeconds(10))
    .Until(ExpectedConditions.ElementTo‌​BeClickable(update.F‌​indElementByName("Al‌​l"))

WinApp 驱动程序的情况可能有点不同,但这是基本思想。