如何为具有双引号的特定Web元素编写xpath?

时间:2019-01-23 08:00:05

标签: selenium selenium-webdriver xpath xpath-1.0

我确定了一个独特的网络元素为:

ng-click="navigateToNewCustomer('New Customer')"

如何为此编写xpath?当我编写xpath时,由于我使用双引号,因此会引发错误。

//*[@ng-click="navigateToNewCustomer('New Customer')"].click();

2 个答案:

答案 0 :(得分:3)

您可以使用反斜杠转义双引号:
//*[@ng-click=\"navigateToNewCustomer('New Customer')\"].click();

答案 1 :(得分:-1)

要将 WebElement 标识为:

webelement ng-click="navigateToNewCustomer('New Customer')"

您可以使用以下两个 XPaths

  • 使用navigateToNewCustomer

    "//*[starts-with(@ng-click,'navigateToNewCustomer')]"
    
  • 使用New Customer

    "//*[contains(@ng-click, 'New Customer')]"
    
  • 使用navigateToNewCustomerNew Customer

    "//*[starts-with(@ng-click,'navigateToNewCustomer') and contains(@ng-click, 'New Customer')]"
    
相关问题