Sunday, June 16, 2013

Selenium: unable to locate element using style attribute with internet explorer

While developing a selenium test and running it on IE,  I was trying to locate an element on the page with xpath, selenium couldn’t find the element, I was getting exception: “NoSuchElementException: Unable to find element with xpath == ……”

I thought at the beginning that there is something wrong with my xpath string, and I kept looking into this for a while. I have installed FirePath plugin for Firefox to verify my xpath, and my xpath was working find, xpath could locate element

Finally I spotted something on selenium documentation under section “IE and Style Attributes” that says that if you are trying to locate an element with the style attribute, it might not work in internet explorer as IE interpret the style parameters in upper case differently that other browsers, so locating with style and lowercase will success in Firefox, Chrome, etc… but will fail in IE


looking back to my xpath, my element xpath was ".//*[@id='ajaxLoadingModalPanelContainer' and contains(@style,'display: none')]"

Changing it to ".//*[@id='ajaxLoadingModalPanelContainer' and contains(@style,DISPLAY: none')]" my test was able to find the element successfully

No comments:

Post a Comment