0

This is my code

<tr>
    <td>
        <div>
            <span>Cloud Email Security</span>
            <input id="productLine_software-0" name="productLine_software" value="Cloud Email Security" type="hidden"/>
        </div>          
    </td>
    <td>
        <div>
            <span>Core</span>
            <input id="productCategory_software-0" name="productCategory_software" value="Core" type="hidden"/>
        </div>      
    </td>
    <td>
        <div>
            <span>Cloud Antispam</span>
            <input id="softwareName_software-0" name="softwareName_software" value="Cloud Antispam" type="hidden"/>
        </div>      
    </td>
    <td>
        <div>
            <div>
                <span>
                    <input id="select_boolean_software_1" type="checkbox" value="1" name="select_boolean_software"/>                        
                </span>
            </div>
        </div>      
    </td>
</tr>
<tr>
    <td>
        <div>
            <span>Cloud Email Security</span>
            <input name="productLine_software" value="Cloud Email Security" type="hidden"/>
        </div>          
    </td>
    <td>
        <div>
            <span>Core</span>
            <input id="productCategory_software-0" name="productCategory_software" value="Core" type="hidden"/>
        </div>          
    </td>
    <td>
        <div>
            <span>Cloud Email Security</span>
            <input name="softwareName_software" value="Cloud Email Security" type="hidden"/>
        </div>          
    </td>
    <td>
        <div>
            <div>
                <span>
                    <input id="select_boolean_software_1" type="checkbox" value="1" name="select_boolean_software"/>                        
                </span>
            </div>
        </div>      
    </td>
</tr>

I am using this CSS selector code in Selenium

css=tr:contains('Cloud Email Security & Content Control') input[type = 'checkbox']

It always select the first row instead of 2nd one. Any thoughts? (I deleted remainig tags becoz the code was really long)

10
  • 1
    You should never use such selectors, if there is a slight chance, that there is another way. Commented Nov 11, 2013 at 3:29
  • Can you not target this with any other selector? First child, last child, nth-child etc Commented Nov 11, 2013 at 3:34
  • I tried many other combinations, but none worked. I want to search for tr which has td with a specific value and specific name and then I need to click on input checkbox on the same tr. Commented Nov 11, 2013 at 3:37
  • And you don't have control over the HTML output I assume? Commented Nov 11, 2013 at 3:38
  • I don't have any control over the HTML Commented Nov 11, 2013 at 3:41

1 Answer 1

1
+50

I did a few few attempts involving the tr tag, both using CSS and XPATH, but seems to me the tr is acting weird in the locator.

If you don't explicitly need to use the tr, and instead can go for the checkbox following your unique input, try this

xpath=//input[@name='softwareName_software' and @value='Cloud Email Security']/following::input[@type='checkbox']

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

3 Comments

Glad to hear it helped :)
Any ideas why TR tag was not working as expected ? In theory, it should
Nah. When I figured the tr didn't work as I expected it to (theory) I just moved on to find an alternative solution. The table structure is a bit complicated; maybe the Selenium implementation can't handle all variants as expected, or maybe there is some additional rules we don't know about.

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.