简体   繁体   English

有人可以帮助我找到带有链接的ng内容的定位器吗?

[英]Can somebody help me with locators for ng-contents with links?

I am trying to click on a header in my application that directs me to another screen. 我试图单击应用程序中的标题,该标题将我定向到另一个屏幕。 However, I observe that the locators are not helping me here. 但是,我发现定位器在这里没有帮助我。 Also the following code does not work: 同样,以下代码不起作用:

element(by.xpath("//a[@routerlink='/opportunities/list']")).click();

The css locator too generated by ChroPath does not work 同样由ChroPath生成的CSS定位器不起作用

element(by.xpath("//a[@routerlink='/opportunities/list']")).click();

enter image description here 在此处输入图片说明

Have you looked at the Protractor documentation ? 您是否看过量角器文档 We also recommend not using xpath because it causes your locator to be brittle and it is hard to debug. 我们还建议不要使用xpath,因为它会使定位器变脆并且难以调试。 There are alternatives to xpath like linkText or just by css. xpath有替代方法,例如linkText或仅由CSS提供。 In the two items below, I'll use async / await which your tests should be using since the control flow will be deprecated. 在下面的两个项目中,我将使用async / wait,因为控制流将被弃用,因此应该使用您的测试。

Option 1 选项1

Your html has text for your link so you want to use the webdriver.By.linkText 您的html包含用于链接的文本,因此您想使用webdriver.By.linkText

await element(by.linkText('opportunities')).click();

Option 2 选项2

You can use css to match attributes and tags: 您可以使用CSS来匹配属性和标签:

await element(by.css('a[routerlink="/opportunities/list"])).click()

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

相关问题 有人可以用一些逻辑来帮助我吗? - Can somebody help me with some logic? 有人可以帮助我吗? 在 React 中找不到问题 - Can somebody help me? Can't find problem in React discord.js中的“未定义”错误,有人可以帮助我吗? - “Undefined” Error in discord.js, can somebody help me? 有人可以帮助我更改Chrome的Google字典扩展的不透明度吗? - Can somebody help me change the opacity of the Google Dictionary Extension for Chrome? 有人可以帮我解决几何变换问题吗? - Can somebody please help me with a geometric transformation problem? 有人可以帮我解码这个。 看起来像 Javascript 或 Json - Can somebody help me decode this. Looks like Javascript or Json 有人可以帮我编写和理解部分应用程序模式吗? - Can somebody help me write and understand the partial application pattern? 有人可以帮我 TypeError: Cannot read property 'map' of undefined - Can somebody help me TypeError: Cannot read property 'map' of undefined 有人可以使用Lodash / Underscore / Javascript / jQuery帮助我吗? - Can somebody help me using Lodash/Underscore/Javascript/jQuery? 有人可以帮助我使用网络应用程序来模拟图像传输吗? - Can somebody help me with a web application for a simulation of transfer of images
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM