【发布时间】:2019-03-16 07:21:45
【问题描述】:
在Robot Framework中,我正在尝试检查源代码中是否存在“XXX”,如下所示:
<button class='btn-aaa'>
<span class='bbb'>
XXX
</button>
我尝试了以下代码,但都失败了:
Page Should Contain Element | //button/span/following-sibling::text()="XXX"
---> Valid xpath but encountering error in Robot Framework with error message "InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //button/span/following-sibling::text()="XXX" because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type."
Page Should Contain Element | //button/span[@class='bbb']/following-sibling::contains(text(),"XXX")
---> Invalid xpath
Page Should Contain Element | //button/span[@class='bbb']/following-sibling::[contains(text(),"XXX")]
---> Invalid xpath
谁能建议在 Robot Framework 中使用正确的 xpath 检查“XXX”的正确方法?
以下是所用工具的信息:
- 机器人框架版本 3.0.4
- Selenium 版本 3.14.1
- Selenium2Library 版本 3.0.0
- Python 3.6.6
已编辑:
我非常感谢你们所有人都在努力提供帮助。非常感谢。 我会尽力提供尽可能多的信息,以便您也可以帮助我。
我试过了:
//button[normalize-space()='View Data']
不幸的是,它什么也没找到。
还有其他按钮,但只有一个带有“查看数据”文本。
这里有更详细的代码。不知道与前面提到的简化版相比是否有帮助:
<button class="btn btn-submit float-left" type="button" onclick="return doActionParam('https://www.blabla.com/blabla',{op:'viewBla',blaId:'wxyz', activeTab:getActiveTabName()})">
<!--groupParent.-->
<span class="bongobongo"></span>
View Data
<button>
希望这次信息对您有所帮助。再次感谢。
附加信息:
浏览器:Mozilla Firefox 62.0.3(64 位)
【问题讨论】:
-
您是否有理由专门使用 xpath 而不是 css 选择器?
-
这只是为了标准化,坚持使用 xpath,因为整个测试自动化脚本都在使用 xpath。如果有更好的方法,请随时提出建议。
-
好吧,我建议使用 css 路径而不是 xpath。 xpath 是明确的,如果项目正在开发中,则必须不断更改。 css 路径不那么脆弱。
-
谢谢,KeithMc18。我会试试看。
标签: xpath robotframework