Muthu Muthu - 4 years ago 181
Python Question

How to locate Angularjs elements by using selenium - python

<button ng-if="vm.signatureRequired" ng-disabled="!vm.signature || vm.signature.length < 2" type="button" aria-hidden="true" data-ng-click="$hide();vm.isAgreement=true;" class="btn btn-default back_btn ng-scope">I Agree</button>

I tried
but its throwing

"raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such
element: Unable to locate element: "

Answer Source

Obviously, your selectors (provided in comments) won't work as:

  • You cannot use find_element_by_class_name() with compound class names
  • You cannot apply find_element_by_link_text() to button elements (but a only)

Try to use following code and let me know if exception still occurs:

driver.find_element_by_xpath('//button[text()="I Agree"]').click()

You also might need to add some time to wait until your button become clickable:

from import By
from import WebDriverWait
from import expected_conditions as EC

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[text()="I Agree"]'))).click()

Another way to solve NoSuchElementException is to check whether you r element located inside frame/iframe block. If so, you need to switch to that frame before handling target element:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download