[英]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();
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,因为控制流将被弃用,因此应该使用您的测试。
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();
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.