Why one should prefer using CSS over XPath in IE?

后端 未结 4 480
再見小時候
再見小時候 2020-12-03 02:18

I am working on an application which is compatible only with IE7 and IE8. I didn\'t know why but some suggested to use CSS over XPath while identifying the elements in IE. W

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 02:55

    Using CSS locator is the best option, not only on IE, also on FF and Chrome. Also, xpath is always the worst choice, because it needs to parse the whole page to find a simple element, so if you want performance in your tests and you can avoid it, just do it.

    Also, if you are using pageObjects I strongly recommend you to use cacheLookup, so the element will be located just once:

    @CacheLookup
    @FindBy(id="doLogin")
    private WebElement loginButton;
    

    Personally, I do the following:

    • If element has css class, use this locator
    • If element has name or id, use this locator
    • If none of the above is present, and you can not use linkText or another locator, go for xpath.

提交回复
热议问题