【问题标题】:How to write dynamic xpath for img src如何为 img src 编写动态 xpath
【发布时间】:2019-03-28 23:10:27
【问题描述】:

我正在尝试从网站上自动化几个 Selenium-TestNg 场景 - http://ecommerce.saipratap.net/checkpersonaldetail.php

我试图单击“继续”按钮,但它似乎是一个图像。 下面是代码的sn-p。如何编写相同的xpath?

尝试使用 xpath - //a[contains(@href,'checkoutshiping.php')],但没有成功

<a href="checkoutshiping.php"> ==$0
    <img src="images/continue.gif" border="0"
     style="cursor:hand;"> ==$0
   </a>

【问题讨论】:

  • 共享错误可能是等待问题?
  • 我收到以下异常 - org.openqa.selenium.NoSuchElementException: Cannot locate an element using xpath=//a[@href='checkoutshiping.php'] 有关此错误的文档,请访问:seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018-11-14T08:25:48' 系统信息:主机:'LENOVO',ip:'192.168.1.101 ', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201' 驱动信息: driver.version: RemoteWebDriver
  • @ChaitanyaMaligi 而不是发布 错误堆栈跟踪 作为评论,这应该是对主要问题的编辑,以便贡献者可以更好地了解您的问题。

标签: selenium xpath


【解决方案1】:

您确定用户已登录吗?检查网站时,我看到了其他一组标签。

你在xpath下面试过了吗?

//*[.='Checkout']

【讨论】:

    【解决方案2】:

    使用 - //a[@href = "checkoutshiping.ph"],它会找到你的按钮。我在你的网站上查过了。

    【讨论】:

    • 我收到以下异常 - org.openqa.selenium.NoSuchElementException: Cannot locate an element using xpath=//a[@href='checkoutshiping.php'] 有关此错误的文档,请访问:seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018-11-14T08:25:48' 系统信息:主机:'LENOVO',ip:'192.168.1.101 ', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201' 驱动信息: driver.version: RemoteWebDriver
    • 这很奇怪,这是您网站上的示例(我添加了屏幕截图),请仔细检查元素名称。
    【解决方案3】:

    这是您网站上的示例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-26
      • 2016-02-18
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 2020-11-05
      相关资源
      最近更新 更多