简体   繁体   English

在python中使用Selenium使用ng-model定位元素

[英]Locating an element using ng-model using Selenium in python

I am trying to automate an AngularJS application using Selenium in python. 我试图在python中使用Selenium自动化AngularJS应用程序。 I am trying to find an element with ng-modal. 我试图用ng-modal找到一个元素。 I have seen some post related to Java which specifies that you can use the following statement 我看过一些与Java相关的帖子,它指定你可以使用以下语句

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

I am trying to do the same in python 我想在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? 我错过了什么,或者还有其他方法吗?

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 : 因为,这是一个Angular应用程序而python-selenium本身并没有等待Angular“安定下来”(例如, protractorpytractor ),你需要明确地等待元素出现

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: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM