使用 cssSelector 查找带有硒化物(Selenium)的特定元素

Finding a specific element with Selenide (Selenium) using cssSelector

如果有像图片中这样的元素结构, 可以像这样取出每个 static-属性 : $$('#static-information .value').get(0) 或 $$('.static-属性 .value').get(0)

但是由于每个静态 属性 在 div 中都有一个唯一的 .key - 如果顺序更改(摆脱使用 get(0)、get(1) 等)。

例如investorFullName = $$('#static-information .key="Name" .value')

或者类似 td[class='key'][value='Name']

如果要通过键查找静态 属性,需要使用 xpath,css 选择器不支持通过文本查找元素。

findPropertybyKey(key) {
   return element(by.xpath('//div[@class="key"][text()="' + key + '"]/..'));
}

readPropertyValuebyKey(key) {
   return findPropertybyKey(key).element(by.css('.value')).getText();
}