javascript - 如何从 div 标签表示的表中检索行和列数据

标签 javascript html selenium xpath uiview

我希望从 div 标签表示的表格的行和列中检索数据。当存在 tbody、tr、td 标签时会更容易,但这里整个表格、行和列使用 div 标签(UI GridView )表示。有人可以帮助我如何继续使用 selenium webdriver 获取数据。任何帮助表示赞赏。

Something like below code:

<div id=table_view>
  <div row = 0>
    <div col =1>
    <div col=2>
  <div row = 1>
    <div col = 1>
    <div col = 2>
</div>

最佳答案

它比下面的通用表迭代要容易得多:-

WebElement table = driver.findElement(By.id("table_view"));

 //Now find all rows
List<WebElement> rows = table.findElements(By.xpath(".//div[@row]"));

for(WebElement row : rows)
{
    List<WebElement> cols = row.findElements(By.xpath(".//div[@col]"));
    for(WebElement col : cols)
    {
        System.out.println(col.getText());
    }
 }

或者您可以直接迭代所有列,如下所示:-

List<WebElement> cols = driver.findElement(By.id("table_view")).findElements(By.xpath(".//div[@col]"));
 for(WebElement col : cols)
 {
     System.out.println(col.getText());
 }

关于javascript - 如何从 div 标签表示的表中检索行和列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39040692/

相关文章:

javascript - 如何在计算属性更改时更改数据?

javascript - 在悬停时在图像上书写

javascript - 使用事件监听器检测按钮的点击,然后增加 html 元素的计数

jquery - jCarouselLite 在与 Bootstrap 一起使用时不起作用

python-3.x - 使用 Selenium 从容器的文本区域获取文本

python-3.x - 我想右键单击并使用 selenium 和 python 在新选项卡中打开链接

javascript - window.location.href 打开另一个窗口

javascript - 如何在javascript中延迟执行for循环

selenium - 为 selenium python 安装 "pip undetected-chromedriver"

javascript - SAPUI5 未捕获类型错误 : jszip is not a constructor