更新时间:2023-08-24 16:49:28
对我来说最简单的方法是访问我在表中查找的用户的 tr,然后单击该行中的按钮编辑.两个例子
Easy way for me was accessing tr of the user I was looking for in the table and then clicking the button edit in this row. Two examples
$username26="testuser26"
element.all(by.xpath('//trLocator')).first().element(by.xpath("//tr[.//td[@data-field='username' and text()="+$username26+"]]")).element(by.xpath(".//a[text()='Edit']")).click()
element(by.xpath("//td[@data-field='username' and text()='"+$username26+"']/..")).element(by.xpath(".//a[text()='Edit']")).click();
要理解的重要部分是第二个 xpath 中的一个点,它表示当前节点.没有这个点//"的字面意思是页面上的任何地方,而.//"则意味着从我已经选择的元素开始
The important part to understand is a dot in the second xpath which means the current node. Without this dot "//" literally mean anywhere on the page vs ".//" which means starting from the element I've already selected
现在这是很长的路要走,但这是我一直在寻找的逻辑
Now this is the long way, but this was the logic I was looking for
var tableRows = element.all(by.xpath('xpathTableRowsLocator')); //returns 11 rows
var mentricsLogo = element(by.css('a.logo'));
var searchedUsername = "TESTUSER26";
//somehow the code didn't work by itself so I had to place it inside of random function whuch I didn't care about
mentricsLogo.isPresent().then(function(result) {
return tableRows.filter(function(eachRow, index) {
//get text of the whole row and separate it by columns
return eachRow.getText().then(function(text){
text=text.split(" ")
// I get third element is username
if (text[2]===searchedUsername){
var xpathIndex = Number(index)+1
element(by.xpath("//*[@id='user-list-content']/div[2]/div[2]/div[1]/div[2]/div[1]/table/tbody/tr["+xpathIndex+"]/td[1]/a")).click()
}
})
});
});
我知道这可能看起来不合理,但没有其他方法对我有用.
I know it may look not rationally, but nothing else worked for me.