Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locating an element using ng-model using Selenium in python

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?

like image 390
KingJames Avatar asked Oct 19 '22 05:10

KingJames


1 Answers

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:

  • Selenium WebDriver and generic wait or delay
like image 149
alecxe Avatar answered Oct 21 '22 23:10

alecxe