5

I am trying to automate an AngularJS application using Selenium in python. I am trying to find an element with ng-modal. I have seen some post related to Java which specifies that you can use the following statement

"//input[@ng-model='yourName']"

I am trying to do the same in python

(By.XPATH, "//*/select[@ng-model='yourName']")

But I am unable to find the element. Am I missing something or is there is some other way of doing it?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
KingJames
  • 546
  • 2
  • 9
  • 20

1 Answers1

3

Since, this is an Angular application and python-selenium does not natively wait for Angular to "settle down" (as, for instance, protractor or pytractor), you need to explicitly wait for the element to become present:

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

wait = WebDriverWait(driver, 10)
elm = wait.until(EC.presence_of_element_located((By.XPATH, "//select[@ng-model='yourName']")))

See also:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Apart from EC.presence_of_element_located, sometimes the element is not yet visible to the user to be interactable, in which case it's better to use EC.visibility_of_element_located – Alichino Jun 13 '16 at 14:22
  • i tried the above code but its not working. nothing happens.i tried both EC.presence and EC.presence. – sunil chayagol Feb 04 '19 at 13:23