赛普拉斯SyntaxError:解析文件时出现意外的令牌,预期为“,”

问题描述

我正在尝试自动化使用React和Sass开发的应用程序。这是我为元素编写的xpath

// span [包含(@ class,'BettingAdd__Single ewp79e31')] / parent :: div / preceding-sibling :: div [2]

自动化工具是赛普拉斯。 VS代码是我用于编写脚本的编辑器。当我使用此xpath并尝试执行我的脚本时,它给出了一个错误

Users/Frontend Automation/cypress/integration/examples/silkpath.spec.js: Unexpected token,expected "," (25:42)

  23 | 
  24 |       
> 25 |         cy.xpath('//span[contains(@class,'BettingAdd__Single               ewp79e31')]/parent::div/preceding-sibling::div[2]').click();
     |                                           ^
  26 | 
  27 |         })
  28 |          while parsing file: /Users/Frontend Automation/cypress/integration/examples/silkpath.spec.js
GET /__cypress/tests?p=cypress/integration/examples/silkpath.spec.js 200 0.496 ms - -
GET /sw.js 200 559.189 ms - -

这是否意味着赛普拉斯无法识别这样的xpath? 有人可以帮我吗?

解决方法

'来使\转义:

cy.xpath('//span[contains(@class,\'BettingAdd__Single       ewp79e31')]/parent::div/preceding-sibling::div[2]').click();