Back

Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
2 views
by (19.9k points)

I am trying to check the checkbox but i am getting following error

selenium.common.exceptions.NoSuchElementException: Message: no such 

element: Unable to locate element: {"method":"xpath","selector":"//mat- 

checkbox[@id='mat-checkbox-1']/label/div"}

I tried selecting using id, css-selector and xpath but keep on getting error.

reg_date_checkbox = self.browser.find_element_by_xpath("//matcheckbox[@id='mat-checkbox-1']/label/div")

reg_date_checkbox.location_once_scrolled_into_view

reg_date_checkbox.click()

The HTML of checkbox is

<div _ngcontent-fep-c23="" class="last-date my-12 ng-star-inserted" fxlayout="column" style="flex-direction: column; box-sizing: border-box; display: flex;">

<mat-checkbox _ngcontent-fep-c23="" class="mat-checkbox mat-accent ng-untouched ng-pristine ng-valid" formcontrolname="deadline_enabled" id="mat-checkbox-1">

    <label class="mat-checkbox-layout" for="mat-checkbox-1-input">

        <div class="mat-checkbox-inner-container">

            <input class="mat-checkbox-input cdk-visually-hidden" type="checkbox" id="mat-checkbox-1-input" tabindex="0" aria-checked="false">

            <div class="mat-checkbox-ripple mat-ripple" matripple="">

                <div class="mat-ripple-element mat-checkbox-persistent-ripple"></div>

            </div>

            <div class="mat-checkbox-frame"></div>

            <div class="mat-checkbox-background">

                <svg xml:space="preserve" class="mat-checkbox-checkmark" focusable="false" version="1.1" viewBox="0 0 24 24">

                    <path class="mat-checkbox-checkmark-path" d="M4.1,12.7 9,17.6 20.3,6.3" fill="none" stroke="white"></path>

                </svg>

                <div class="mat-checkbox-mixedmark"></div>

            </div>

        </div><span class="mat-checkbox-label"><span style="display:none">&nbsp;</span>The event has a registration deadline</span>

    </label>

</mat-checkbox>

<!---->

1 Answer

0 votes
by (25.1k points)

This is because you are trying to click on the element which is not of the type 'checkbox'. You should use the code below:

reg_date_checkbox = self.browser.find_element_by_xpath("//input[@id='mat-checkbox-1-input']")

reg_date_checkbox.click()

Related questions

0 votes
1 answer
+2 votes
2 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...