0

I'm trying to check the checkbox using Selenium. This is the element of the checkbox.

<div class="ams-item-text ng-binding" ng-bind-html="amssh.create_label(item)" ng-click="toggle_check_node(item)" role="button" tabindex="0">all contract signed</div>

I'm directly copying the x-path of this element and wrote the below code:

browser.find_element_by_xpath('//*[@id="advancedcontents"]/div/div/div[2]/div/div[1]/div[1]/div/div/div[2]/div[2]/div/div[2]/div[3]/div[2]').click()

But it won't never click the check box that I wanted, but click the check box way below, which is with this:

<div class="ams-item-text ng-binding" ng-bind-html="amssh.create_label(item)" ng-click="toggle_check_node(item)" role="button" tabindex="0">future</div>

What could be the issues? I try the checkbox element, or the text element (also clickable) but both doesn't work.

1
  • Can you share the link? Commented Apr 7, 2020 at 21:29

3 Answers 3

1

To click on dynamic element induce WebDriverWait() and visibility_of_element_located() and following xpath option.

WebDriverWait(browser,10).until(EC.visibility_of_element_located((By.XPATH,"//div[@class='ams-item-text ng-binding' and text()='all contract signed']"))).click()

You need to import following libraries.

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
Sign up to request clarification or add additional context in comments.

Comments

1

Try below code:

    wait = WebDriverWait(browser, 20)
    wait.until(EC.element_to_be_clickable(By.XPATH, "//div[contains(.,'all contract signed')]")).click()

Note : Add below imports to your solution

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

7 Comments

Hi thank you for the reply! I tried but I get the following error: NameError: name 'driver' is not defined
should be browser in your case check above solution
Hi... So sometimes the code (not just the above code, but in general when I try to find element) works but when I try again a few times, it stops working. Do you know why?
I get an error message that says Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@name='daterangepicker_start']"} but the code was working well previously.
Yes use it to avoid synchronization issues
|
-1

"ams-item-text ng-binding"browser.find_element_by_xpath('//*[@id="advancedcontents"]/div/div/div[2]/div/div[1]/div[1]/div/div/div[2]/div[2]/div/div[2]/div[3]/div[2]').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.