1

I am new to Selenium I have been following the documentations but they seem outdated.

(for curious people, that is the admin section of Atlassian's Cloud https://admin.atlassian.com/s/orgID/users/userID, I wish to remove site access for multiple users)

Here is a subset of the HTML page:

<label data-size="regular" class="css-ji2l50" data-checked="true">
    <input name="" type="checkbox" value="123456789abcde">
        <span role="img" aria-label="check" class="css-zg81aj">
            <svg width="24" height="24" viewBox="0 0 24 24" role="presentation">
                <path d="M7.356 10.942a.497.497 0 00-.713 0l-.7.701a.501.501 0 00-.003.71l3.706 3.707a.501.501 0 00.705.003l7.712-7.712a.493.493 0 00-.006-.708l-.7-.7a.504.504 0 00-.714 0l-6.286 6.286a.506.506 0 01-.713 0l-2.288-2.287z" fill="currentColor"></path>
            </svg>
        </span>
        <span role="img" aria-label="cross" class="css-zg81aj">
            <svg width="24" height="24" viewBox="0 0 24 24" role="presentation">
                <path d="M15.185 7.4l-3.184 3.185-3.186-3.186a.507.507 0 00-.712.003l-.7.701a.496.496 0 00-.004.712l3.185 3.184L7.4 15.185a.507.507 0 00.004.712l.7.7c.206.207.516.2.712.004l3.186-3.185 3.184 3.185a.507.507 0 00.712-.004l.701-.7a.496.496 0 00.003-.712l-3.186-3.186 3.186-3.184a.507.507 0 00-.003-.712l-.7-.7a.508.508 0 00-.36-.153.5.5 0 00-.353.15z" fill="currentColor" fill-rule="evenodd"></path>
            </svg>
        </span>
</label>

I want to capture and click on <input name="" type="checkbox" value="123456789abcde">

Since there is no element = driver.find_element(By.VALUE,"123456789abcde") (link to the documentation)
I am using element = driver.find_element(By.XPATH, "//input[@value='123456789abcde']")

This seems to work fine, print(element) gives <selenium.webdriver.remote.webelement.WebElement (session="b2d92d7e20334085b7989c009fa77785", element="c23fdd99-9052-4028-9a72-e8f39873c720")>

But element.click() results in a ElementClickInterceptedException exception. element.click does return <bound method WebElement.click of <selenium.webdriver.remote.webelement.WebElement (session="b2d92d7e20334085b7989c009fa77785", element="c23fdd99-9052-4028-9a72-e8f39873c720")>> but the button is not toggled.
enter image description here

What am I doing wrong? Note that I am using Edge webdriver if that matters.

Thanks.

EDIT: From first investigations, it seems that the the <label> is overlapping the input. If I indeed click on the label itself it does toggle the button. In the page code above, I tested my code on the xpath driver.find_element(By.XPATH, "//label[@data-checked='true']").click() but the thing is that there are several labels on the page that show a data-checked='true' property. How to craft the xpath so that I select the label associated with that specific input. Basically mixing the "//label[@data-checked='true']" and //input[@value='123456789abcde'] xpaths.

8
  • We need an access to that page in order to debug and see what exactly appears there. Generally ElementClickInterceptedException exception means that when you tried to click some element another element received the click. To make a simple check try adding a sleep before clicking that element. In case it worked we will improve that Commented Sep 2, 2022 at 10:14
  • Hi, I am actually executing the commands one by one so I do not think a sleep will solve the issue. Unfortunately the source page is not accessible. It is always possible for you to open a Jira cloud site then go to the "user management" section. Thanks for your answer anyway. Commented Sep 2, 2022 at 10:17
  • If so there should be some element hovering that element. Commented Sep 2, 2022 at 10:19
  • 1
    Also, performing the commands one by one is done during debugging only. In the real code run it will work differently ... Commented Sep 2, 2022 at 10:21
  • 1
    That says your locator is correct. Also JavaScript can click any element: out of the view, below other elements etc. While Selenium behaves as a human user. As a user you can't click element inside drop list before you open it etc. Commented Sep 2, 2022 at 10:23

1 Answer 1

1

Since we have no access to that page we can only guess.
So, instead of driver.find_element(By.XPATH, "//input[@value='123456789abcde']").click() Try adding a wait. The WebdriverWait is the preferred way to do that, as following:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 20)

wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@value='123456789abcde']"))).click()

UPD
In case you need to click the label element which is a direct parent of this input the locator can be updated as following:

wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@value='123456789abcde']/.."))).click()

Another way to precisely locate that label is to find the parent div based on the child input and from it to get the child label as following:

wait.until(EC.element_to_be_clickable((By.XPATH, "//div[.//input[@value='123456789abcde']]//label"))).click()
Sign up to request clarification or add additional context in comments.

2 Comments

I receive a TimeoutException. Seems like the element is never clickable. Though in the developer console it is. document.evaluate("//input[@value='123456789abcde']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click()
Sure, as I said before, seems that there is some other element overlaps it. To resolve this I need an access to that page....

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.