2

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)

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.