0
<ul>

                    <li>
                        <label class="checkbox">
                            <input checked="checked" id="fechapublicacion" name="fechapublicacion" onclick="javascript: filtrarListado(&#39;fechapublicacion&#39;, this);" type="radio" value="0" />
                            <span>Cualquier fecha</span>
                        </label>
                        <input id="fechapublicacionhidden" name="fechapublicacionhidden" type="hidden" value="0" />
                    </li>
                    <li>
                        <label class="checkbox">
                            <input id="fechapublicacion" name="fechapublicacion" onclick="javascript: filtrarListado(&#39;fechapublicacion&#39;, this);" type="radio" value="1" />
                            <span>&#218;ltimas 24 horas</span>
                        </label>
                        <input id="fechapublicacionhidden" name="fechapublicacionhidden" type="hidden" value="0" />
                    </li>
                    <li>
                        <label class="checkbox">
                            <input id="fechapublicacion" name="fechapublicacion" onclick="javascript: filtrarListado(&#39;fechapublicacion&#39;, this);" type="radio" value="7" />
                            <span>&#218;ltimos 7 d&#237;as</span>
                        </label>
                        <input id="fechapublicacionhidden" name="fechapublicacionhidden" type="hidden" value="0" />
                    </li>
                    <li>
                        <label class="checkbox">
                            <input id="fechapublicacion" name="fechapublicacion" onclick="javascript: filtrarListado(&#39;fechapublicacion&#39;, this);" type="radio" value="15" />
                            <span>&#218;ltimos 15 d&#237;as</span>
                        </label>
                        <input id="fechapublicacionhidden" name="fechapublicacionhidden" type="hidden" value="0" />
                    </li>
            </ul>

I am trying to select the last radio button. Since all of them have same id, how can i select the last one.

Any help will be appreciated.

4
  • Is that the entire html? Because the one which you have given to me works pretty well with: paste.fedoraproject.org/411153/47169496 Commented Aug 20, 2016 at 12:09
  • This is the link : 'infoempleo.com/ofertas-internacionales'. There are four check boxes. I need to select the last one. All the check boxes have the same id. So i guess selecting by id will select the first check box. How can i select the last one? Commented Aug 20, 2016 at 12:29
  • 1
    browser.find_elements_by_id("fechapublicacion")[-1].click() ? Commented Aug 20, 2016 at 12:32
  • @NehalJWani Thanks. Got it fixed. Commented Aug 20, 2016 at 12:35

2 Answers 2

2

Actually find_elements returns list that's why you are in trouble, you should try using find_element instead as below :-

browser.find_element_by_id("fechapublicacion").click()

Or if you want to use find_elements, You should try using index in returned list as below :-

browser.find_elements_by_id("fechapublicacion")[0].click()

Edited :- As I'm seeing in provided HTML, I'd is not unique there and you want to select last element with the id then try using find_elements and select last element by passing last index as -1 :

browser.find_elements_by_id("fechapublicacion")[-1].click()

Or you can also use find_element to point this element using unique css_selector as below :-

browser.find_element_by_css_selector("input#fechapublicacion[value='15']").click()
Sign up to request clarification or add additional context in comments.

7 Comments

Got this fixed, but still the radio button is not being selected. What can be the reason for that?
Is there any exception when you are going to click??
And make sure provided Id is unique and you are locating correct element..
Actually the id is not unique. There are four radio buttons with same id. I will edit the question
Ok then which one you want to select??
|
0

You are using find_elements.... which returns a list. Use findelement or getelement which returns one element(i got no idea abt python functions). Or else use an index 0 to findelements. it is saying it is trying yo find a click method on a list which it aint got

Comments

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.