0

I am a newbie to css, html, etc and thus cssselectors. I have been messing around with selenium webdriver and am trying to .click() the following button:

<button title="" class="btn addWidgButt bt-block" href="" role="button" type="button"     context="UNIQUE_THING">
<span class="btn-text">UNIQUE THING</span></button>

According to http://www.w3.org/TR/css3-selectors/#selectors shouldn't the following selector work? (Rule is E[foo="bar"] for element E

By.cssSelector("button title[context=UNIQUE_THING]")
By.cssSelector("btn.addWidgButt.bt-block[context=UNIQUE_THING]")
By.cssSelector("span[btn-text=UNIQUE THING]")

I think the last one is my best bet, as span is an element and btn-text is an attribute value. Any help is appreciated, thanks.

Dax Durax
  • 1,607
  • 5
  • 23
  • 31
  • One thing you can do to test your CSS selectors: Open the web page in Chrome. Hit F12 for dev tools. Ctrl+F for find. Paste your selector in the search box. It will show you the number of matches. – Richard Jan 29 '14 at 20:02

1 Answers1

0

One thing I noticed is that all of your selectors in [] are missing single quotes.

By.cssSelector("button[context='UNIQUE_THING']")
By.cssSelector(".btn.addWidgButt.bt-block[context='UNIQUE_THING']")
By.cssSelector("span.btn-text")

Your second selector is missing the leading .

Your last selector will not work, as you cannot match text with CSS Selectors. You can match a class with ., or id with #.

For more information, this is an excellent reference: http://www.w3schools.com/cssref/css_selectors.asp

Richard
  • 8,961
  • 3
  • 38
  • 47