夜间值班.单击带有文本的元素 [英] Nightwatch. Click on element with text

查看:46
本文介绍了夜间值班.单击带有文本的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,无法点击具有某些唯一文本的网络元素. 我有这个结构:

I have a problem, can`t click on web element having some unique text. I have this structure:

<div class="wg-wagon-type__item"  data-reactid="10"
  <div class="wg-wagon-type__title" data-reactid="11">Text</div>

我尝试

.click('.wg-wagon-type__title:contains("Text")')

但是我有一个错误

ERROR: Unable to locate element: ".wg-wagon-type__item .wg-wagon-type__title:contain("Text")" using: css selector

如何正确点击此元素?

推荐答案

是否有任何原因不能使您直接定位类wg-wagon-type__title?

Is there any reason why you can't simply target the class wg-wagon-type__title?

.click('.wg-wagon-type__title')

不幸的是,没有一个与元素文本匹配的CSS选择器.但是,nightwatch可以通过"api.execute"在浏览器上运行javascript,并允许您进行字符串匹配.

Unfortunately there isn't a CSS selector that matches on the text of an element. However, nightwatch has the capability to run javascript on the browser via 'api.execute' and that allows you to do string matching.

或者,您可以使用xpath选择器并使用它来匹配文本

Alternatively, you could use an xpath selector and use that to match the text

.click("//div[contains(@class, 'wg-wagon-type__title') and text()='Text']")

这篇关于夜间值班.单击带有文本的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆