在python中使用Selenium使用ng-model查找元素 [英] Locating an element using ng-model using Selenium in python

查看:212
本文介绍了在python中使用Selenium使用ng-model查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在python中使用Selenium来自动化AngularJS应用程序.我正在尝试使用ng-modal查找元素.我看过一些与Java相关的帖子,其中指定您可以使用以下语句

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']"

我试图在python中做同样的事情

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?

推荐答案

因为这是一个Angular应用程序,所以python-selenium本身不会等待Angular安顿下来"(例如, 明确等待元素出现 :

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']")))

另请参阅:

这篇关于在python中使用Selenium使用ng-model查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆