【问题标题】:Selenium cant access any elements on the webpageSelenium 无法访问网页上的任何元素
【发布时间】:2021-03-25 17:28:22
【问题描述】:

我正在使用 Specflow 和 Nunit 在 C# 中为我正在处理的一个新项目编写 Selenium 测试,body 中的任何内容都无法在任何地方选择

可以通过

访问正文
WaitUntil(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("body")));

不能以下工作和 throe 元素未找到异常:

WaitUntil(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("halo-root")));
WaitUntil(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("halo-entry")));`
WaitUntil(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("halo-navigation-container")));

错误:没有这样的元素:无法找到元素:{"method":"css selector","selector":"halo-root"}

  • 没有 iframe
  • 我已经尝试过长时间等待以确保它没有异步
  • 网站是 angular.js(我尝试了一些量角器方法,但没有成功)
  • 我也玩过ElementIsVisibleElementIsClickable 等等
  • 我尝试了不同的选择器(id、className、xpath 等)

感谢所有帮助

p.s 无法共享整个 SUT,因为它需要 vpn 访问权限。

【问题讨论】:

  • 可能是 JAVA 正在运行,您必须等待 JAVA 完成。所以你可能必须循环直到元素不为空。
  • 如果网址是公开的,能发一下吗?
  • "

标签: c# angularjs selenium


【解决方案1】:

首先检查您的 html。我认为 body 标签必须存在于 iframe 中。 如果它存在于 iframe 中,请先切换到 iframe,然后尝试对元素执行任何命令(等待或操作)。

【讨论】:

    【解决方案2】:

    问题是通过门户(Jumpcloud)登录时打开了一个新选项卡(我没有注意到),因此解决方案只是使用_driver.SwitchTo().Window(_driver.WindowHandles[1]) 切换到该新窗口

    感谢所有的帮助! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      相关资源
      最近更新 更多