我如何找到量角器查看网页源代码的元件,在其他的观点和不可见 [英] How do I locate elements in protractor that are in other views and are not visible when viewing page source

查看:163
本文介绍了我如何找到量角器查看网页源代码的元件,在其他的观点和不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的角和放大器;量角器(为此事和网络开发),所以我的道歉,这是一个明显的问题。

I am new to Angular & Protractor (and web development for that matter), so I apologize of this is an obvious question.

我试图用量角器来检验我们的角度应用程序,看来,我可以在页面上找到的第一个元素。但找不到任何使用(编号,名称,型号,CSS)的其他元素。我曾尝试过链接的第一要素,但总是找不到错误链中的第二个元素的元素。我已经有三重检查拼写所以我相信一切是正确的。

I am trying to test our angular app with protractor, and it appears that I can locate the first element on the page. But cannot find any of the other elements using (id, name, model, css). I have tried chaining off of the first element, but always get the element not found error on the second element in the chain. I've have triple check the spelling so I am confident everything is correct.

我们的网页是设置了多个部分,当我查看源文件我只看到根分区。

Our page is setup up with multiple sections and when I "view source" I only see the root div.

<head>
</head>
<body>

<div ng-app="app" id="wrap">
    <div ui-view></div>
</div>

</body>
</html>

但是,当我检查使用的开发工具(F12)的元素,他们在DOM存在的,我只是不知道如何让他们。

But when I inspect the elements using the developer tools (F12), they exist in the DOM, I just don't know how to get to them.

<input type="text" class="form-control ng-valid ng-dirty ng-valid-parse ng-touched" data-ng-model="vm.searchText" id="searchText" placeholder="(Account # / Name / Nickname / Phone #)">

我试图访​​问使用上面​​列出的控制以下内容:

I tried to access the control listed above using the following:

browser.element(by.id("searchText").sendKeys("test");
browser.element(by.model("vm.searchText").sendKeys("test");
element(by.id("searchText").sendKeys("test");
element(by.model("vm.searchText").sendKeys("test");

我也创建一个单一的按钮,用于partialButtonText&放大器; buttonText,无论是其中的工作。

I also create a single button and used partialButtonText & buttonText, neither of which worked.

我也试过用然后,但没有任何工作增加一些异步功能。我如何访问这些元素都在一个HTML文件中不包含?

I also tried to add some async functionality with "then" but that didn't work either. How do I access these elements are are not contained in a single html file?

感谢.....

推荐答案

不要有口碑点在评论中添加这user2020347的反应如此......当你查看源文件,在我又不相信你再谈到动态生成的内容。而不是使用查看源代码或者使用Chrome或Firefox开发者工具,以确保你使用正确的定位器。

Don't have the reputation points to add this in the comments to user2020347's response so...When you say not in "view source" I assume you're talking about dynamically generated content. Instead of using view source either use chrome or firefox developer tools to make sure you're using the right locators.

例如在Chrome的控制台一旦页面加载以下应返回结果:
$$('#SEARCHTEXT')
$$('输入[数据-NG-模式=vm.searchText]')

For example in chrome's console the following should return a result once the page is loaded: $$('#searchText') $$('input[data-ng-model="vm.searchText"]')

它也像你发送键相同的元素。

It also looks like you're sending keys to the same element.

既然你有一个角应用量角器等所有元素加载,但以防万一,你可能要等待元素是present和/或在网页上显示。

Since you have an angular app protractor should wait for all elements to load, but just in case you might want to wait for the element to be present and/or visible on the page.

这篇关于我如何找到量角器查看网页源代码的元件,在其他的观点和不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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