简体   繁体   English

如何使cssSelector在IE 9中查找元素

[英]How to get cssSelector to Find a Element in IE 9

如何使用IE9中的开发人员工具查找cssSelector?

Pro-tip, you shouldn't be using tools to "find" or "create" selectors for you - why? 专业提示,您不应该使用工具为您“查找”或“创建”选择器-为什么? Tools are going to give you the basic selector, which is not necessarily the best one. 工具将为您提供基本的选择器,它不一定是最好的选择器。

Therefore, you need to look at and understand the CSS selector spec and actually create them yourself. 因此,您需要查看并了解CSS选择器规范 ,并亲自创建它们。

However, once you've created the selectors yourself it is quite easy to actually "run" them in IE's Developer Tools. 但是,一旦您自己创建了选择器,就可以很容易地在IE的开发人员工具中“运行”它们。 You just need to mimic what Selenium does. 您只需要模仿Selenium的功能即可。

Example selector: #someID > div.something 选择器示例: #someID> div.something

In IE's Developer Tools, open up the Console, and type in: 在IE的开发人员工具中,打开控制台,然后输入:

document.querySelector("selector")

Which, in my example, is: 在我的示例中,这是:

document.querySelector("#someID > div.something")

This is equivalent to your .FindElement calls, and as for your .FindElements calls: 这等效于您的.FindElement调用,以及您的.FindElements调用:

document.querySelectorAll("selector")

Which, in my example, is: 在我的示例中,这是:

document.querySelectorAll("#someID > div.something")

The result you get back, is what (in theory) Selenium should also be finding. 从理论上来说,您应该得到的结果就是硒。

You should use firefox and add ons firebug and firepath to get the right xpath. 您应该使用firefox并添加ons firebug和firepath以获得正确的xpath。 When executing tests define the browser internet explorer or chrome or firefox or etc instead 执行测试时,请定义浏览器Internet Explorer或chrome或firefox等

firebug https://addons.mozilla.org/nl/firefox/addon/firebug/ 萤火虫https://addons.mozilla.org/nl/firefox/addon/firebug/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM