如何在Xpath中使用by.css,以及如何用相同的路径类来区分两个元素。

问题描述 投票:0回答:1

我有这两个xpaths。

 /html/body/ion-app/ng-component/ion-nav/page-settings/ion-content/div[2]/ion-grid/ion-row[2]/ion-col[1]/ion-input
    /html/body/ion-app/ng-component/ion-nav/page-settings/ion-content/div[2]/ion-grid/ion-row[2]/ion-col[2]/ion-input

我如何用元素by.css来测试它们?

如何区分两个路径是否 "相等",如上图所示?

both elements

html css xpath protractor
1个回答
0
投票

你不能使用xpath与 by.css,而且只有在 by.xpath

如果你想用等价的css来给定xpath,这是很基础的知识,可以查一下。这里有一个非常好的资料 https:/devhints.ioxpath。

虽然第二个问题应该是单独的一个帖子,但我也要回答一下。在你这个特殊的例子中,输入的内容并不完全相同。

X路径。

  1. //*[@ng-reflect-model="GG"]/input
  2. //*[@ng-reflect-model="Test"]/input

但是在假设的情况下 当你有两个元素有相同的属性时 你可以指定使用哪一个出现-- (//xpath)[1] (选择第一个匹配的),或者说是哪个孩子--------。//xpath/to/firstChild[1]

© www.soinside.com 2019 - 2024. All rights reserved.