1

Please see the image below which shows code of the web page in Developer Tools window and advise me the correct selector for 'Depreciation Models'. Text highlighted in red is constant, however the surrounding text is dynamic. So I tried using contains selector to locate but unsuccessful. I want to avoid XPATH as number of before and after div elements may keep changing.

I am using Selenium IDE hence the C#/Java code for RC/Webdriver won't help much.

Web Page Code in Developer Tools

Selenium IDE generated target path is this:

css=#dhxId_rgWATog7lC3E_27572|6059|6152 > td.sub_item_text > div.sub_item_text

I tried

css=contains('27572') > td.sub_item_text > div.sub_item_text

but it didn't work.

Kindly suggest. I am stuck. Thanks.

Community
  • 1
  • 1
jainashish
  • 4,702
  • 5
  • 37
  • 48

2 Answers2

1

I guess this would be the right approach:

<style>
   [id*="27572"] > td.sub_item_text > div.sub_item_text{
      color:red;
   }

<table>
        <tbody>
            <tr id="dhxId_rgWATog7lC3E_27572|6059|6152" class="sub_item">
                <td class="sub_item_icon">
                     <i class="fa fa-user epc-down-circled-2"></i>
                </td>
                <td class="sub_item_text">
                     <div class="sub_item_text"> Depriciations Models</div>
                </td>
            </tr>
        </tbody>
    </table>

It will set all elements that have an id attribute value containing "27572" and inside of it.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
slon
  • 1,002
  • 1
  • 8
  • 12
1

As you tried the Locator Strategy as :

css=contains('27572') > td.sub_item_text > div.sub_item_text

Reasons for not working

The :contains pseudo-class isn't in the CSS Spec and is not supported by either Firefox or Chrome (even outside WebDriver).

Solution

You can use the following xpath as per the existing DOM Tree:

xpath=//tr[@class='sub_item'][contains(@id,'27572')]//td[@class='sub_item_text']/div[@class='sub_item_text'][contains(.,'Depreciations Models')]
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352