在 Python 中使用带有 Selenium 的 Angular JS(量角器)

问题描述

我正在尝试使用 selenium 选择一个包裹在 angular 1 中的文本区域,但在 DOM 中看不到它.有一个名为 Pytractor 的模块.我一直在尝试解决这个问题,但我无法正确使用它.

I'm trying to select a textarea wrapped in angular 1 using selenium, but it can't be seen in DOM. There's a module called Pytractor. I've been trying to solve this but I'm unable to use it correctly.

谁能帮我解决这个问题?

Can anyone help me with this?


解决方案

您还可以使用常规 selenium 绑定来测试 AngularJS 应用程序.您需要使用 显式等待 来等待元素出现、消失、标题/要更改的 URL 等 - 任何可以让您继续测试页面的操作.

You can also use regular selenium bindings to test AngularJS applications. You would need to use Explicit Waits to wait for elements to appear, disappear, title/url to change etc - for any actions that would let you continue with testing the page.

示例(等待 textarea 元素出现):

Example (waiting for textarea element to appear):

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

wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.TAG_NAME, "myaccount")))

<小时>

pytractor(作为 protractor 本身)提供了一件重要的事情 - 它知道 AngularJS 何时完成并准备就绪 - 模型会更新,没有未完成的异步请求等.这并不意味着您必须使用它来测试 AngularJS 应用程序,但它会给您带来优势.


There is one important thing that pytractor (as protractor itself) provides - it knows when AngularJS is settled and ready - models are updated, there are no outstanding async requests etc. It doesn't mean you have to use it to test AngularJS applications, but it gives you an advantage.

此外,pytractor 为您提供了新的定位器,例如您可以通过模型或绑定找到元素.这也不意味着您无法使用 的其他定位技术找到相同的元素常规 selenium python 提供了开箱即用的.

Additionally, pytractor provides you with new locators, e.g. you can find an element by model or binding. It also doesn't mean you cannot find the same element using other location techniques which regular selenium python provides out-of-the-box.

请注意,pytractor 目前并未积极开发和维护.

Note that pytractor is not actively developed and maintained at the moment.

相关文章