微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Selenium Webdriver - 等到用户单击没有 ID 的按钮

如何解决Selenium Webdriver - 等到用户单击没有 ID 的按钮

我在 Chrome 中使用 Selenium Webdriver 和 Excel VBA 自动化,但在等待用户点击按钮时遇到了一些问题。

网页代码如下:

web code

我尝试过 FindElementByCss、FindElementByID...,还有 IsPresent、IsEnabled...但没有任何效果。现在小米代码如下:

t = Timer
    do while bot.FindElementById("ui-button-text").IsPresent = True
        bot.Wait 500
        If Timer - t = 10 Then Exit Do 'Para evitar bucle infinito
    Loop

提前致谢!

解决方法

根据 HTML:

66044675

ui-button-textclass 属性的值,但不是 id 属性的值,并且有多个 {{ 1}} 元素的 <span> 属性值为 class,具有不同的 textContent


要验证元素的存在,您可以使用以下 Locator Strategies

  • 文本为Cancelar的元素:

    • 使用 xpath

      ui-button-text
  • 文本为Repetir的元素:

    • 使用 xpath

      Do While bot.FindElementByXPath("//span[@class='ui-button-text' and text()='Cancelar']").IsPresent = True
      
  • 文本为 Aceptar 的元素:

    • 使用 xpath

      Do While bot.FindElementByXPath("//span[@class='ui-button-text' and text()='Repetir']").IsPresent = True
      

要验证元素是否启用,您可以使用以下Locator Strategies

  • 文本为Cancelar的元素:

    • 使用 xpath

      Do While bot.FindElementByXPath("//span[@class='ui-button-text' and text()='Aceptar']").IsPresent = True
      
  • 文本为Repetir的元素:

    • 使用 xpath

      Do While bot.FindElementByXPath("//span[@class='ui-button-text' and text()='Cancelar']").IsEnabled = True
      
  • 文本为 Aceptar 的元素:

    • 使用 xpath

      Do While bot.FindElementByXPath("//span[@class='ui-button-text' and text()='Repetir']").IsEnabled = True
      

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。