falek.marcin
falek.marcin

Reputation: 10659

problem: Getting to the element by using CSS selectors attribute 'style' with selenium

I'm having trouble getting to the element using the 'style' attribute with selenium. The problem is that using xpath selectors I am able to do it:

int(self.selenium.get_element_index("//div[contains(@class,'%s')][contains(@style,'%s')][contains(@style,'%s')]"%(pin_class_name,map_object_position[0],map_object_position[1])))

^ This returns result

But when I try to get to the element using css selectors, it appears that such an element not found:

int(self.selenium.get_element_index("css=div[class*='%s'][style*='%s'][style*='%s']"%(pin_class_name,map_object_position[0],map_object_position[1])))

Has anyone met with this problem or knows if it is possible to navigate using the attribute 'style' using css selectors. I describe this problem, because I want to make a comparison with the use of both methods (I suspect that the use of xpath doesn't as it should)

Upvotes: 2

Views: 1624

Answers (2)

Michael Sorens
Michael Sorens

Reputation: 36748

I did extensive experimentation comparing and contrasting XPath, CSS, and DOM locators for Selenium and found that while one can access the style attribute from XPath or DOM, one cannot from CSS (just as you surmised). You can find that tidbit (see Footnote 2), along with my complete analysis, in my quick reference chart XPath, CSS, DOM and Selenium: The Rosetta Stone, recently published on Simple-Talk.com.

Upvotes: 3

Ross Patterson
Ross Patterson

Reputation: 9569

The *= operator isn't in CSS2, so depending on the version of Selenium you're using, it may not be available to you.

Upvotes: 0

Related Questions