英文:
Unable to delete all the records from table but its deleting only one record using selenium java
问题
尝试在添加产品后删除移除按钮
使用循环逐个删除记录,然后在退出测试用例之前
但只删除一个记录,我想要删除记录直到表格计数为零
List<WebElement> rows = driver.findElements(xpath);
// 循环如下
for (int i = 0; i < rows.size(); i++) {
// 通过以下方式访问单个元素:
WebElement deleteButton = driver.findElement(xpath);
deleteButton.click();
}
英文:
Trying to delete remove button after adding the products
used for loop to delete the records one by one before signout the testcase
But its deleting only one record ,i would like to delete the records until its reach to table count zero
` List<WebElement> rows = driver.findElements(xpath);
// For loop follows
for (int i = 0; i < rows.size(); i++) {
// Access individual elements this way:
WebElement deleteButton = driver.findElement(xpath);
deleteButton.click();
}`
答案1
得分: 0
请参考以下翻译:
可能你应该从每行的根元素开始搜索。
看起来你在循环中每次都试图点击相同的元素。
试试这样做:
<!-- 开始代码片段: js 隐藏: false 控制台: true Babel: false -->
<!-- 语言: lang-js -->
List<WebElement> rows = driver.findElements(rowsXpath);
// 循环如下
for (WebElement element: rows) {
// 这样访问单个元素:
WebElement deleteButton = element.findElement(deleteButtonXpath);
deleteButton.click();
// 我建议在这里添加一些等待以确保行数减少
}`
<!-- 结束代码片段 -->
英文:
Probably you should search from root element from each row.
It looks like you are trying to click on the same element in your loop each time.
Try this
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
List<WebElement> rows = driver.findElements(rowsXpath);
// For loop follows
for (WebElement element: rows) {
// Access individual elements this way:
WebElement deleteButton = element.findElement(deleteButtonXpath);
deleteButton.click();
// there I suggest to add some wait for rows amount to be decreased
}`
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论