3

I can’t get selenium to click on this checkbox button no matter what I do.

Error:

no such element: Unable to locate element:

I have used sleep thread timers and wait.until(ExpectedConditions.visibilityOfElementLocated()).

Here is the HTML of the button:

<input id="1_2_null" type="checkbox" name="1.0.50.gecb16" xgc="" rownumber="1">

I have tried :

driver.findElement(By.xpath("//*[@id=\'1_2_null\']")).click();
driver.findElement(By.name("1.0.50.gecb16")).click();
driver.findElement(By.id("1_2_null")).click();

It's possibly inside this iframe:

<iframe frameborder="no" width="100%" height="100%" src="" id="maincontent" name="maincontent"></iframe>
  • 1
    Probably your element is inside frame or iframe? – Alexey R. Dec 11 '19 at 16:18
  • Thank you, how do I check for that? – user42676 Dec 11 '19 at 16:19
  • 1
    Using browser dev tools look at the parent nodes starting from your input to the root node. Check if one of the nodes is frame or iframe – Alexey R. Dec 11 '19 at 16:43
  • 1
    Thanks Alexey R. I belive its inside this <iframe frameborder="no" width="100%" height="100%" src="" id="maincontent" name="maincontent"></iframe> – user42676 Dec 11 '19 at 16:55
  • 6
    Does this answer your question? Selenium - How to interact with elements on Iframe – Alexey R. Dec 11 '19 at 18:31
0

There could be two reasons for that

1.) your element is not present on the same frame

ii.) the id of the element is dynamic, you can use startswith, endswith or Contains methods of xpath.

if you can share the Exception, I would be more specific on what might be causing that issue

|improve this answer|||||
0

If checkbox ID is not dynamic, you can try to have explicit wait for that element's visibility as: element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "myDynamicElement"))

Here, 10 is the maximum time to wait and you can increase it at max as per your need.

|improve this answer|||||

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