0

I have recently moved from using xpaths to CSS selectors given the need of the project. I am new to the use of these locators and need to know if there is any way through which I can write text based CSS selectors for my Web Elements.

I found some sources like [ https://sauceio.wordpress.com/2010/03/19/selenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class/ ] and [ https://saucelabs.com/resources/articles/selenium-tips-css-selectors ] which suggest that CSS selectors allow text based locators using contains pseudo-class but I am not able to write them using this approach. Is there any way through which I can write text based CSS locators for the web elements?

  • similar question https://stackoverflow.com/questions/6648238/what-to-use-instead-of-contains-in-css3 – Fan Cheung Sep 26 '17 at 12:12
  • This community is for helping people to when they stuck with actual implementation. Please give it a try on your on and post the difficulty you are facing during implementtaion with the sample code you have tried – Vijayanath Viswanathan Sep 26 '17 at 12:13
  • Possible duplicate of [Is there a CSS selector for elements containing certain text?](https://stackoverflow.com/questions/1520429/is-there-a-css-selector-for-elements-containing-certain-text) – Tom Sep 26 '17 at 13:14

1 Answers1

0

First you have to do some work , This is the link which helps you to understand how to use cssSelector

- Using Id

CSS Selector Rule - #id

    <button id="submitButton1" type="button" class="btn">Submit</button>
CSS Locator - `#submitButton1`

Description - '#submitButton1' will select the element with id 'submitButton1'.

- Using class

CSS Selector Rule - .class

    <button id="submitButton1" type="button" class="btn">Submit</button>

CSS Locator - `.btn`

Description - '.btn' will select all the elements with class 'btn'.

http://artoftesting.com/automationTesting/css-selector-in-selenium-webdriver.html

iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
  • I need information regarding writing the css selector with the inner html text. The answer tells ways of writing the css selector with non-text based methods. – Shivarshi Sep 26 '17 at 15:16