Nightwatch无法通过css id或类选择器定位元素 [英] Nightwatch can't locate element via css id or class selectors

查看:130
本文介绍了Nightwatch无法通过css id或类选择器定位元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Nightwatch自动执行一些UI测试。一些当前的测试相当脆弱,主要与奇怪的CSS选择器有关,我正在尝试简化它们。但是,我期望工作的一些简单的CSS选择器是,不是。

We're using Nightwatch to automate some of our UI testing. Some of the current tests are rather brittle, mostly having to do with weird CSS selectors, and I'm trying to simplify them. But some of the simple CSS selectors that I would expect to work are, well, not.

我试图找到这个深度嵌套的< ; a> 代码:

I'm trying to find this deeply nested <a> tag:

<a class="btn btn-quote btn-crm" href="/crm/" id="btnEndSession" style="display: inline-block;">End Session</a>

以下是一些有效的代码:

Here's a bit of code that's working:

.waitForElementVisible('#quoteSummary > div > div > div > div > a:nth-child(2)', 1000)
.click('#quoteSummary > div > div > div > div > a:nth-child(2)')

但那是一个令人讨厌的CSS选择器,我想用它替换它:

But that's a nasty CSS selector, and I'd like to replace it with this:

.waitForElementVisible('#btnEndSession', 1000)
.click('#btnEndSession')

As我感兴趣的< a> 元素确实具有 btnEndSession 的id,看起来像是应该管用。但事实并非如此:夜间观察错误,其中一个在等待元素时超时< #btnEndSession>可见10000毫秒消息。

As the <a> element I'm interested in does in fact have the id of btnEndSession, it seems like that should work. But it doesn't: nightwatch errors out with one of its "Timed out while waiting for element <#btnEndSession> to be visible for 10000 milliseconds" messages.

I还尝试过:

.waitForElementVisible('.btn-crm', 10000)
.waitForElementVisible('a[id=btnEndSession]', 10000)
.waitForElementVisible('a#btnEndSession', 10000)

但那些也不起作用。知道为什么这些简单的选择器没有选择元素吗?

But those don't work either. Any idea why these simpler selectors aren't picking the element up?

编辑:

好的,奇怪的是,这有效:

OK, weirdly enough, this worked:

.waitForElementVisible('a.btn-crm', 1000)

但是,在同一个测试中,寻找这个元素:

However, in the same test, looking for this element:

<select class="custom-form-control crm-result-visit select-hidden" id="crm-result-visit" name="crmResultVisit">
    <option value=" ">Select</option>
    <option value="Not Home">Not Home</option>
</select>

所有这些不同的选择器都找不到元素:

All of these different selectors fail to find the element:

.waitForElementVisible('select.crm-result-visit', 10000)
.waitForElementVisible('select#crm-result-visit', 10000)
.waitForElementVisible('#crm-result-visit', 10000)
.waitForElementVisible('.crm-result-visit', 10000)
.waitForElementVisible('select[id=crm-result-visit]', 10000)

我有点不情愿地得出CSS选择器支持的结论在夜间表中很漂亮。

I'm sort of reluctantly driven to the conclusion that the CSS selector support in nightwatch is pretty buggy.

FWIW,我们使用的是0.6.7版的夜视仪。

FWIW, we're using version 0.6.7 of nightwatch.

推荐答案

为了它的价值,我们最终放弃了Nightwatch,直接进入Selenium(在我们的例子中是C#),这似乎没有这些问题,并且更好地集成到其余的我们的环境。不是很好的答案,但我不再有这个问题: - )。

For what it's worth, we ended up abandoning Nightwatch, and going straight to Selenium (C#, in our case), which didn't seem to have these problems, and integrated better into the rest of our environment. Not a great answer, but I don't have this problem anymore :-).

这篇关于Nightwatch无法通过css id或类选择器定位元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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