Selenium IDE and xpath - find text / row in table and select radio box

23,689

The problem with your xpath is that td and input are not sibling (they don't have common parent) and even if you change your xpath to more correct version:

//input[@type='radio']/following::td[1]/a[contains(text(),'testing')]

it will find a that have preceding checkbox instead of checkbox itself. So correct xpath will be:

//a[contains(text(),'testing')]/preceding::input[@type='radio'][1]

or

//tr[descendant::a[contains(.,'testing')]]//input[@type='radio']

For xpath axis tutorial read this: http://msdn.microsoft.com/en-us/library/ms256456.aspx

Share:
23,689
Damien
Author by

Damien

Just moved back to Australia after 18yrs in the UK Now: Hugo content management, shortcodes and theme components Past: WordPress plugin developer / technical dev lead I use Hugo

Updated on May 23, 2020

Comments

  • Damien
    Damien about 4 years

    I've been using Selenium IDE and getting some good results. I've done a lot of reading about following-sibling and preceding-sibling but I can't locate the right radio button.

    Essentially I want to find the row in a table with the word 'testing' and then click the radio button in the cell.

    So far I can find the input button //input[@type='radio']

    and find the text testing //a[contains(text(),'testing')]

    I've been trying to use this in the ide

    check | //input[@type='radio']/following-sibling::td[1]/a[contains(text(),'testing')]
    

    but I get the error [error] locator not found: //input[@type='radio']/following-sibling::a[contains(text()[1],'testing')]

    Any help to change this is really appreciated :)

    Cheers

    Damien

    here's the bare basic table ...

    <tbody id="list">
    <tr>
    <th>
    <label class="radio">
    <input class="presentation_radio" type="radio" value="1" name="presentation_radio">
    </label>
    </th>
    <td>
    <a href="/link_to/document">testing </a>
    </td>
    <td>testing</td>
    <td>Joe Acme</td>
    <td>Presentation</td>
    <td>03 May 2012</td>
    <td>5 (1)</td>
    </tr>
    </tbody>
    
  • BoltClock
    BoltClock about 12 years
    Where is CSS mentioned in this question?
  • Damien
    Damien about 12 years
    Hey thanks for this ... this one works //a[contains(text(),'testing')]/preceding::input[@type='radi‌​o']
  • Aleh Douhi
    Aleh Douhi about 12 years
    @Damien sorry, it should be with [1] in the end. See my corrected answer.
  • Damien
    Damien about 12 years
    @AlehDouhi Yes i see ... it always selects the th in row 1 otherwise