2

I am trying to target specific CSS elements on a page, but the problem is that they have varying selector names. For instance, input#dp156435476435.textinput.wihtinnextyear.datepicker.hasDatepicker.error. I need to target the CSS because i am specifcally looking for the .error at the end of the element, and that is only in the CSS (testing error validation for fields on a website. I know if I was targeting class/name/href/id/etc, I could use xpath, but I'm not aware of a partial CSS selector in selenium webdriver. Any help would be appreciated, thanks!

1
  • Have you considered just iterating through the entire document tree and testing each element for your CSS attribute? Commented Feb 13, 2014 at 21:16

3 Answers 3

3

The period/full stop is a partial class selector:

span.error

would find:

<span class="error" />
<span class="error warning" />
<span class="critical error" />

You also have:

span[class^='error']

(begins with)

span[class$='error']

(ends with)

span[class*='error']

(contains)

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

Comments

0

If the page has similar elements, you can combine what Arran said like so:

driver.find_element_by_css_selector( "input[id^='dp'][class*='nextyear'][class$='error']" )

Comments

0

css=span.error -- Error

css=span.warning -- Warning

css=span.critical -- Critical Error

Simple above are the CSS Selectors we can use.

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.