使用Selenium导航通过DIV元素创建的HTML表
我有一个使用“div”元素创建的表,它具有基于选择的动态内容以及要显示的数据 我想找到一种方法来点击表格最后一行的一些图标。无法使用getElementID执行此操作,因为如果有多行,则所有图标都具有相同的ID。是否有其他方法可以执行此操作使用Selenium导航通过DIV元素创建的HTML表,html,selenium,getelementbyid,Html,Selenium,Getelementbyid,我有一个使用“div”元素创建的表,它具有基于选择的动态内容以及要显示的数据 我想找到一种方法来点击表格最后一行的一些图标。无法使用getElementID执行此操作,因为如果有多行,则所有图标都具有相同的ID。是否有其他方法可以执行此操作 <div class="cv-layout"> <div class="row cv-layout-body"> <div class="mobile-col-12 tablet-col-12 deskt
<div class="cv-layout">
<div class="row cv-layout-body">
<div class="mobile-col-12 tablet-col-12 desktop-col-12 settlement-container cv-panel">
<div class="row header">
<div class="tablet-col-1">Ref</div>
<div class="tablet-col-2">Rec</div>
<div class="tablet-col-2">Amt</div>
<div class="tablet-col-3">Say</div>
<div class="tablet-col-3 text-right">Pay</div>
<div class="tablet-col-1 center-text">Age</div>
</div>
<div class="settlement-item">
<div class="row settlement-read-item bordered">
<div class="tablet-col-1">Col1Row1</div>
<div class="tablet-col-2">Col2Row1</div>
<div class="tablet-col-2"><span>Col2aRow1</span>
</div>
<div class="tablet-col-3">
<div>
<div>
<p><span class="item-header prevent-break">Value: 356 €</span>
</p>
</div>
</div>
</div>
<div class="tablet-col-3 text-right">
<div>
<p><span class="item-header prevent-break"><span>XZS $34</span>
<!-- react-text: 1647 -->
<!-- /react-text --><span>BAS $321</span></span>
</p>
</div>
</div>
<div class="tablet-col-1">
<div class="center-text"><span class="icon-unconfirmed confirm link-icon "></span><span class="icon-edit link-icon edit"></span><span class="icon-delete link-icon remove"></span>
</div>
</div>
</div>
</div>
裁判
记录
金额
说
支付
年龄
Col1Row1
Col2Row1
Col2arw1
价值:356欧元
XZ$34
BAS 321美元
您可以在最后一行找到类似的内容(我正在使用Python):
然后单击行中的图标:
unconfirmed_icon = last_row.find_element_by_css_selector("span.icon-unconfirmed")
unconfirmed_icon.click()
您可以在最后一行找到类似的内容(我使用的是Python): 然后单击行中的图标:
unconfirmed_icon = last_row.find_element_by_css_selector("span.icon-unconfirmed")
unconfirmed_icon.click()
其思想是首先找到要对其执行操作的表,然后导航到特定行并执行操作 当我们知道行的内容时,下面的代码将起作用,在这种情况下,我们将执行getText并比较值。如果找到值,将单击并退出循环,这将有助于保持动态
List<WebElement> tableElement = driver.findElements(By.xpath("//div[contains(@class,'settlement-item')]")); // findElements will return a list of table elements
for (WebElement webElement : tableElement) {
if (webElement.getText().contains(rowData)) { //rowData is the data value which we are looking for to perform operation on
webElement.click();
break;
}
List tableElement=driver.findElements(By.xpath(“//div[contains(@class,'collection-item')]);//findElements将返回一个表元素列表
for(WebElement WebElement:tableElement){
如果(webElement.getText().contains(rowData)){//rowData是我们要查找的要对其执行操作的数据值
webElement.click();
打破
}
List<WebElement> tableElement =
driver.findElements(By.xpath("//div[contains(@class,'settlement-item')]")); // findElements will return a list of table elements
int index = tableElement.size();
tableElement.get(index-1).click();
}
List tableElement=
findElements(By.xpath(“//div[contains(@class,'consolution-item')]”);//findElements将返回表元素列表
int index=tableElement.size();
tableElement.get(index-1)。单击();
}
其思想是首先找到要对其执行操作的表,然后导航到特定行并执行操作 当我们知道行的内容时,下面的代码将起作用,在这种情况下,我们将执行getText并比较值。如果找到值,将单击并退出循环,这将有助于保持动态
List<WebElement> tableElement = driver.findElements(By.xpath("//div[contains(@class,'settlement-item')]")); // findElements will return a list of table elements
for (WebElement webElement : tableElement) {
if (webElement.getText().contains(rowData)) { //rowData is the data value which we are looking for to perform operation on
webElement.click();
break;
}
List tableElement=driver.findElements(By.xpath(“//div[contains(@class,'collection-item')]);//findElements将返回一个表元素列表
for(WebElement WebElement:tableElement){
如果(webElement.getText().contains(rowData)){//rowData是我们要查找的要对其执行操作的数据值
webElement.click();
打破
}
List<WebElement> tableElement =
driver.findElements(By.xpath("//div[contains(@class,'settlement-item')]")); // findElements will return a list of table elements
int index = tableElement.size();
tableElement.get(index-1).click();
}
List tableElement=
findElements(By.xpath(“//div[contains(@class,'consolution-item')]”);//findElements将返回表元素列表
int index=tableElement.size();
tableElement.get(index-1)。单击();
}
您没有在模板中的任何位置使用
id=”“
。您可以使用查询字符串进行选择,如.link icon.确认,.link icon.编辑,.link icon.删除-或者您可以为这些操作提供更好的命名。您可以使用CSS选择器匹配类或XPath来表示与另一个元素的关系。您可以向我们展示您的工作吗?Thanks@DebanjanB抱歉,没有收到您的评论。你想看什么作品?你没有在模板中的任何地方使用id=”“
。您可以使用查询字符串进行选择,如.link icon.确认,.link icon.编辑,.link icon.删除-或者您可以为这些操作提供更好的命名。您可以使用CSS选择器匹配类或XPath来表示与另一个元素的关系。您可以向我们展示您的工作吗?Thanks@DebanjanB抱歉,没有收到您的评论。你想看什么作品?