0

我正在尝试使用 selenium-webdriverjs 编写浏览器测试。当我调用以下代码片段时,我得到错误:错误响应:13。

browser.waitForCondition('var element = document.querySelector(".selector"); var style = document.defaultView.getComputedStyle(element,null); style =' + btnColor ,timeout);

我正在等待一个条件,我想从从 css 选择器获得的元素中获取计算的 css 样式。然后将计算出的 css 样式与名为 btnColor 的变量进行比较。(我知道使用称为 getComputedCss 的 Webdriver JS API 方法也可以做同样的事情。但是,我有兴趣使用 waitForCondition 来实现相同的目的。)

我想知道如何正确使用 waitForCondition 来实现我想要做的事情,以及为什么代码片段会抛出错误。

提前致谢!

4

1 回答 1

1

我找到了这个问题的答案。我在表达式中犯了几个 javascript 错误。以下是我用来解决问题的代码片段。

browser.waitForCondition('var element = window.document.querySelector(".selector"); var style = window.document.defaultView.getComputedStyle(element,null).getPropertyValue("background-color"); style ="' + btnColor + '"',timeout);

1)为了使用文档,您需要先调用窗口对象。
2) 为了得到计算出来的背景颜色,我需要使用 .getPropertyValue() 方法。
3) btnColor 包含一个字符串。因此,我需要在它周围加上双引号,以便解释器将其识别为字符串。

于 2013-09-24T18:04:30.293 回答