2

I have a website in which I need to identify/read the text inside and which in turn inside tag as shown below:

<div class="col-sm-4 execution-data-container">
    <div>...</div>
    <div>
        <label>
            <Strong>Submitted</Strong>
        </label>
    </div>
    <div>...</div>
    <div>...</div>
</div>    

I prefer to use CSS Selector for that is our project preference. I tried to do like this:

//div[@class='col-sm-4 execution-data-container']/div/div/label/Strong[text() = 'Completed']

and:

div.col-sm-4.execution-data-container > div > div > 
label.text()

and:

div.col-sm-4.execution-data-container > div > div > 
label[text()='Completed']

By building a CSS Selector, I want to obtain the text 'Submitted'.

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
PraNuta
  • 629
  • 3
  • 12
  • 33

2 Answers2

0

You can try this way to get the CSS Sector.See If this helps.

".col-sm-4 >div>div>div>label>strong"
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

You can't locate elements by contained text using CSS selectors. You can only do this using XPath.

Your XPath is pretty close... you just had an extra /div/ level that wasn't needed.

//div[@class='col-sm-4 execution-data-container']/div/label/strong[.='Submitted']

If you really want to use a CSS selector, you can use

String status = driver.findElement(By.cssSelector("div.col-sm-4.execution-data-container > div > label > strong")).getText();

which returns 'Submitted'.

JeffC
  • 22,180
  • 5
  • 32
  • 55