2

I have the following html code, i am unable to select the check box.

<table style="overflow:hidden;" cellpadding="0" cellspacing="0" border="0" role="presentation" class="table-header">
<tbody>
 <tr>
  <td class="cell-container cell-container-0 cell-selector locked xwtTable_1562932879200_0" role="presentation" columnidx="0" style="vertical-align: middle;width: 0px;" tabindex="0" aria-readonly="true">
    <div class="cell cell-0 ellipsis no-wrapping cell-selector ellipsis no-wrapping xwtTable_1562932879200_0" role="columnheader" style="text-align: center;" title="">
    <div tabindex="0" class="xwtSelectAll dijitCheckBox" "="" style="visibility:visible">
          <input type="checkbox" class="select-all" style="visibility:visible">
    </div>
 </div>
</td>
</tr>
</tbody></table>

I am getting timeoutexception:

element =wait.until(EC.element_to_be_clickable((By.XPATH, "//div//input[@class='select-all']")))

ERROR [338.067268s]: test_login (main.TestHome)

Traceback (most recent call last): File "TestHome.py", line 55, in test_login s.filterclick() File "C:/Users/rakadali/PycharmProjects/CMM1\Pageobjects\searchdevice.py", line 25, in filterclick WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='table-header']/tbody/tr/td//div[contains( @class, 'dijitCheckBox')]/input[@class='select-all']"))).click() File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

below is the code:

def filterclick(self):

    try:
        wait = WebDriverWait(self.driver, 80)
        element =wait.until(EC.element_to_be_clickable((By.XPATH, "//div//input[@class='select-all']")))
        element.click()
    finally:
        self.driver.close()

i want to select the check box

4 Answers 4

0

Try following xpath to click on the checkbox.

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//table[@class='table-header']//tr//td//input[@class='select-all']"))).click()
0

To select the check box you need to induce WebDriverWait for the desired element_to_be_clickable() and you can use the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "table.table-header>tbody>tr>td div.dijitCheckBox>input.select-all"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='table-header']/tbody/tr/td//div[contains(@class, 'dijitCheckBox')]/input[@class='select-all']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
1
  • Can you update the question with the error stack trace? Commented Jul 15, 2019 at 9:53
0

It might be the case the checkbox is not clickable as it's overlapped with another object, i.e. parent div, try removing the explicit wait and attempt to click the checkbox directly like:

driver.find_elements_by_xpath("input[@class='select-all']").click()

The WebDriver should report the error stating why the element can not be clicked which should give you insight regarding the element which received the click.

You can also try clicking the parent div like:

element =wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@class='select-all']/parent::div")))

Check out XPath Axes and XPath Operators & Functions articles to learn more about building complex XPath locators

Other things to consider:

  • make sure that the table is not in an iframe
  • make sure that the table is not in a Shadow Dom
  • make sure that there are no modal popups like cookie consent banner are present at the page
1
  • tried with this driver.find_element_by_xpath("input[@class='select-all']").click() saying no such element exception
    – Rajani
    Commented Jul 15, 2019 at 10:33
0

line 25, in filterclick WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='table-header']/tbody/tr/td//div[contains( @class, 'dijitCheckBox')]/input[@class='select-all']"))).click()

It seems that you are using absolute xpath which might gets changed while execution and checkbox therefore is no longer visible with this xpath. The exception is very clear. It says "I was waiting for this checkbox for last 80 seconds but it did not showed on UI and now I am done waiting for it." Simply make sure that the element is available on UI within the given time and is searchable with correct selector that you provide.

Not the answer you're looking for? Browse other questions tagged or ask your own question.