本文介紹了硒動態(tài)生長表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在使用 selenium 處理動態(tài)增長表時遇到了一些麻煩.快速總結(jié)一下,在我的網(wǎng)絡(luò)應(yīng)用程序中,我有一個包含 30 個項目的表格,但它只顯示前 20 個項目,我們必須向下滾動才能顯示其余項目.而且我不知道如何在不向下滾動的情況下獲取第 26 個(例如)項目.
I have some troubles to handle dynamic growing table with selenium. To sum up quickly, on my web app I have a table with 30 items but it only displays the twenty first items and we have to scroll down to display the rest. And I don't know how to get the 26th (for example) items without scrolling down.
我的 HTML:
<table id="tableID" tabindex="0" aria-multiselectable="true" role="grid">
<thead>
<tbody id="tableID-tblBody">
<tr id="item1" role="row" tabindex="-1">
<tr id="item2" role="row" tabindex="-1">
[... 17 more]
<tr id="item20" role="row" tabindex="-1">
</tbody>
</table>
滾動后:
<table id="tableID" tabindex="0" aria-multiselectable="true" role="grid">
<thead>
<tbody id="tableID-tblBody">
<tr id="item1" role="row" tabindex="-1">
<tr id="item2" role="row" tabindex="-1">
[... 27 more]
<tr id="item30" role="row" tabindex="-1">
</tbody>
</table>
如果有人可以幫助我,那就太好了^^
謝謝!
If someone could help me it would be great ^^
Thanks!
推薦答案
我會滾動到表中最后一行的視圖(如果需要多次,直到獲得所需的行數(shù)).為此,我將通過 executeScript()
使用 scrollIntoView()
:
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].scrollIntoView();", element);
其中元素
:
WebElement element = driver.findElements(By.xpath("http://table[@id = 'tableID']//tr[last()]")).
這篇關(guān)于硒動態(tài)生長表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!