Selenium python checkbox by span class



  • I have an issue with checkbox check in selenium python, I want to make not exact xpath, but something like I did earlier in the code : browser.find_element_by_xpath(".//span[contains(text(), 'Dalej')]").click() but it was in differend coding

    exact Xpath of checkbox: /html/body/div[2]/div/div[1]/div[2]/div[4]/form/div[1]/div/div/div/div[2]/div/div/div[1]/div[1]/div/div/fieldset/label/span[1]

    checkbox is in:

    <span class="o-ci"></span>
    

    I want to make some simple find element click, that not include exact XPATH, because I want to test page (source, divs can change, I want to secure my scrpt for that, and lock on something elese)

    source code:

    <fieldset>
        <legend class="u-acc-hide">Potwierdź, że akceptujesz regulamin i wyrażasz wszystkie zgody
                </legend>
        <label class="o-checkbox  ">
            <input type="checkbox" data-type="master" class="" name="agreement-master" aria-required="false">
                <span class="o-ci"></span>
                <span class="o-ci-label">
                    Tak
                    </span>
            </label>
        </fieldset>
    


  • If you need to match the

    <input type="checkbox">
    

    which is before the

    <span class="o-ci">
    

    you could go for something like:

    //span[@class='o-ci']/preceding-sibling::input
    

    Demo:

    enter image description here

    More information:



Suggested Topics