Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过css获取css值并在Selenium中使用_Javascript_Css_Testing_Selenium_Selenium Ide - Fatal编程技术网

Javascript 通过css获取css值并在Selenium中使用

Javascript 通过css获取css值并在Selenium中使用,javascript,css,testing,selenium,selenium-ide,Javascript,Css,Testing,Selenium,Selenium Ide,我试着得到一些细胞的颜色,并用硒进行比较 当我这样说的时候: javascript:window.getComputedStyle(document.getElementById("simple_cname"),null).getPropertyValue("background-color"); 在Chrome Omnibox中,我收到了正确的答案,但当我使用storeEval或assertEval尝试获取此值时,它无法正常工作。 编辑: 我把selenium命令放在这里。我使用storeE

我试着得到一些细胞的颜色,并用硒进行比较

当我这样说的时候:

javascript:window.getComputedStyle(document.getElementById("simple_cname"),null).getPropertyValue("background-color");
在Chrome Omnibox中,我收到了正确的答案,但当我使用storeEval或assertEval尝试获取此值时,它无法正常工作。 编辑: 我把selenium命令放在这里。我使用storeEval,当我回显该值时,它会返回此命令。我使用Firefox。我使用Chrome只是为了检查命令是否正确。它应该是rgb220,22,92 编辑2: 是的,这个命令还可以,但是我在Selenium IDE工具中使用它时遇到了一个问题。当我将其与storeEval命令一起使用时,它不会返回值。 日志: [info]脚本是:var test javascript:window.getComputedStyledocument.getElementByIdsimple\u cname,null.getPropertyValuebackground-color;回声试验; [info]正在执行:| echo |${test}|| [info]echo:var test javascript:window.getComputedStyledocument.getElementByIdsimple\u cname,null.getPropertyValuebackground-color;回声试验

我把selenium命令放在这里。我使用storeEval,当我回显该值时,它会返回此命令。 我使用Firefox。我使用Chrome只是为了检查命令是否正确。它应该是rgb220、22、92

您需要删除javascript:part并将文档称为window.document。然后,该命令将如下所示:

window.getComputedStyle(window.document.getElementById('simple_cname'),null).getPropertyValue('background-color');
只有在从URL栏运行代码时才需要javascript:part,它在其他任何地方都是多余的。在Chrome中使用而不是Omnibox来运行JS命令

文档->window.document内容在storeEval部分中提到


另外,请注意,您的脚本只能在现代浏览器中工作,在IE<9时将失败。如果你同意的话,好的。如果没有,.

您确定没有将javascript:部分留在测试用例中吗?您试图在哪个浏览器中运行代码?Selenium IDE仅适用于Firefox,AFAIK。。。是否存在任何类型的错误,或返回空字符串?[info]正在执行:| storeEval | window.getComputedStyledocument.getElementByIdsimple_cname,null.getPropertyValuebackground-color;|测试|[info]脚本为:window.getComputedStyledocument.getElementByIdsimple\u cname,null.getPropertyValuebackground-color;[info]正在执行:| echo |${test}|[info]echo:window.getComputedStyledocument.getElementByIdsimple_cname,null.getPropertyValuebackground-color;此外,没有:。只是代码本身。请记住,它不是一个真正的HTML页面,它只是用作程序运行时的标记。起初我尝试不使用它,但随后出现如下错误:[info]脚本是:window.getComputedStyledocument.getElementByIdsimple_cname,null.getPropertyValuebackground-color;[错误]引发异常:操作不受支持。那么window.getComputedStylewindow.document.getElementByIdsimple\u cname,null.getPropert呢‌​背景色?你的js代码很好,我用Selenium重写了它,而不是复制,它工作了——一些编码问题和一个小时的工作。该死非常感谢你的帮助!