对于我的自动化测试用例,我需要遍历网格以找到刚刚注册的人,以便我可以执行必要的操作。我试图通过xpath这样做,但我注意到的是,虽然网格中有超过100行,但是当我执行以下操作时,它只返回31行:
List<WebElement> RowCount=driver.findElements(By.xpath("//*[@id='grid']/div[5]/div/div/div[3]"));
System.out.println(RowCount.size());
通过以下方式加载网格:
<div class = "grid-widget">
<div id = "grid" style="width:99%;height:700px;">Loading...</div>
<div id="pager_grid" style="width:99%;height:20px;"></div>
</div>
<script>
var grid_grid;
var dataView_grid;
</script>
</div>
html是:
<div class="ui-widget-content slick-row even" style="top:0px">
<div class="slick-cell l0 r0">
<div class="slick-cell l1 r1" title="">test</div>
<div class="slick-cell l2 r2 active" title="James010315075108">James010315075108</div>
<div class="slick-cell l3 r3">test</div>
<div class="slick-cell l4 r4">12/04/1992</div>
<div class="slick-cell l5 r5">test</div>
<div class="slick-cell l6 r6">test</div>
<div class="slick-cell l7 r7">test</div>
<div class="slick-cell l8 r8"></div>
<div class="slick-cell l9 r9">test</div>
<div class="slick-cell l10 r10">test</div>
<div class="slick-cell l11 r11"></div>
<div class="slick-cell l12 r12">test@test.com</div>
<div class="slick-cell l13 r13">Pending</div>
</div>
<div class="ui-widget-content slick-row odd" style="top:25px">
<div class="slick-cell l0 r0">
<div class="slick-cell l1 r1">test</div>
<div class="slick-cell l2 r2">David010415075207</div>
<div class="slick-cell l3 r3">test</div>
<div class="slick-cell l4 r4">12/04/1992</div>
<div class="slick-cell l5 r5">test</div>
<div class="slick-cell l6 r6">test</div>
<div class="slick-cell l7 r7">test</div>
<div class="slick-cell l8 r8"></div>
<div class="slick-cell l9 r9">test</div>
<div class="slick-cell l10 r10">test</div>
<div class="slick-cell l11 r11"></div>
<div class="slick-cell l12 r12">test@test.com</div>
<div class="slick-cell l13 r13">Pending</div>
</div>
<div class="ui-widget-content slick-row even" style="top:50px">
<div class="slick-cell l0 r0">
<div class="slick-cell l1 r1">test</div>
<div class="slick-cell l2 r2">Roger010415081309</div>
<div class="slick-cell l3 r3">test</div>
<div class="slick-cell l4 r4">12/04/1992</div>
<div class="slick-cell l5 r5">test</div>
<div class="slick-cell l6 r6">test</div>
<div class="slick-cell l7 r7">test</div>
<div class="slick-cell l8 r8"></div>
<div class="slick-cell l9 r9">test</div>
<div class="slick-cell l10 r10">test</div>
<div class="slick-cell l11 r11"></div>
<div class="slick-cell l12 r12">test@test.com</div>
<div class="slick-cell l13 r13">Pending</div>
当我列出特定列的xpath大约15行时,我看到已经有大约2-3次重复。
在这种情况下如何遍历网格?任何帮助深表感谢。
答案 0 :(得分:1)
通过执行以下操作,我能够访问我想要的xpath:
By byXpath2 = By.xpath("//div[contains(text(),'" + Name + "')]/../div/select[contains(concat(' ', @class, ' '), ' editor-select ')]");
WebElement element2 = driver.findElement(byXpath2);
act.sendKeys(element2, "r").build().perform();
感谢@Saifur的帮助。
答案 1 :(得分:0)
List<T>
Selenium支持复合类,我看到了活跃用户的类重要性。你可以用它。哪个行
可以与By byCss = By.cssSelector(".slick-cell.l2.r2.active");
css选择器一起使用。但是,我没有看到依赖于特定div
的原因,因为您(可能)正在寻找具有活动类的用户,这可以通过以下方式轻松完成。注意:我假设活动类仅在网格中使用一次,并且仅用于您要查找的活动用户。
By byCss = By.cssSelector(".active");
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(byCss));
//do whatever you need to do here