0

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>
<!---->

3 Answers 3

1

You are probably trying to click on the element which is NOT of type 'checkbox'. I see there is an input with type checkbox. Please try below mentioned code

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

Additionally if you wish you perform uncheck you can look for input element's aria-checked property to be true before performing a click.

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

Comments

0

You are using this xpath //matcheckbox[@id='mat-checkbox-1']/label/div , it should be //mat-checkbox[@id='mat-checkbox-1']/label/div , there's a - in between, you are missing that.

Still you can try with this css selector :

div.mat-checkbox-inner-container input[class^='mat-checkbox-input'][id^='mat-checkbox']

There may be chances that the checkbox is in iframe, if it is the case then first switch to frame and then try to click on check box.

3 Comments

i am getting the following error selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input class="mat-checkbox-input cdk-visually-hidden" type="checkbox" id="mat-checkbox-2-input" tabindex="0" aria-checked="false"> is not clickable at point (421, 64). Other element would receive the click: <div class="mat-checkbox-inner-container">...</div>
When you do it manually, do you scroll down or do you use any kind of action to interact with element.
Ok, Can you try with actions class ?
0

You could try this:

element = self.browser.find_element_by_css("input#mat-checkbox-1-input")
element.click()

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.