OpenQA.Selenium.NoSuchElementException: '没有这样的元素: 无法找到元素: {“method”:“css selector”,“selector”:“.body”}

OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"css selector","selector":".body"}

提问人:chocho 提问时间:11/15/2023 最后编辑:chocho 更新时间:11/20/2023 访问量:46

问:

我正在做自动化测试。在这里,我正在测试一个模态。在 Visual Studio 中,它显示错误。我正在使用 C# 编程语言

OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"css selector","selector":".body"}

如何处理这种模式?此模式不会通过按钮触发。触发器是 JavaScript onload,其中模态将在登录后自动显示。

Enter image description here

driver.SwitchTo().Frame(driver.FindElement(By.ClassName("body")));
driver.SwitchTo().Frame(driver.FindElement(By.ClassName("modal-open")));

在此处输入图像描述

这张图片来自 Inspect Element

C# 硒网络驱动程序

评论

0赞 Saidamir 11/15/2023
我认为您应该使用预期条件,等到模态出现,然后运行测试代码,如果它没有出现,则引发错误或跳过。
1赞 pcalkins 11/16/2023
这看起来根本不像一个框架......可能只是一个 DIV。定位器以名为“body”的类(css 样式)为目标,该类不存在。
0赞 chocho 11/16/2023
我已经尝试使用没有开关框的 CSS 选择器,但仍然没有被 Selenium 检测到。因为这个模态使用 DOM javascript。柔性
0赞 pcalkins 11/17/2023
右键单击模式并选择“检查”。将该元素的 HTML 标记复制/粘贴到您的帖子中。

答: 暂无答案