Java 使用Selenium web驱动程序滚动表格并在列表中存储数据
我正在做一个我想做的项目 1.滚动网页。 2.链接存储在表中 3.单击行中存在的链接Java 使用Selenium web驱动程序滚动表格并在列表中存储数据,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在做一个我想做的项目 1.滚动网页。 2.链接存储在表中 3.单击行中存在的链接 ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)"); List<WebElement> req = driver .findElements(By.xpath("//table[@class='forceRecordLayout uiVi
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
List<WebElement> req = driver
.findElements(By.xpath("//table[@class='forceRecordLayout uiVirtualDataGrid--default uiVirtualDataGrid forceVirtualGrid resizable-cols']//tr"));
int total_req = req.size();
System.out.println(total_req);
for (int i = 0; i < total_req; i++) {
String reqToClick = req.get(i).getText();
if (reqToClick.equalsIgnoreCase("UPC_ 762016_Product Test- 06-07-2016 0")) {
Thread.sleep(3000);
req.get(i).click();
Thread.sleep(3000);
break;
}
}
((JavascriptExecutor)driver.executeScript(“window.scrollTo(0,document.body.scrollHeight)”);
列表请求=驱动程序
.findElements(By.xpath(“//table[@class='forceRecordLayout uiVirtualDataGrid--默认uiVirtualDataGrid forceVirtualGrid可调整大小的cols']//tr”);
int total_req=req.size();
系统输出打印项次(总需求);
对于(int i=0;i
上面是我将数据存储到列表中的代码,但是页面没有向下滚动。列表显示的是不带滚动的计数。请帮助我。这将不会向下滚动页面,而是将web表中的所有链接放入列表,然后单击您需要的链接。
public void ClickLink(字符串链接)
public void ClickLink(string link)
{
//scroll to table.
Actions action = new Actions(driver);
action.MoveToElement(driver.FindElement(By.Id("tableID"));
//get elements in list
List<WebElement> req = driver.findElements(By
.xpath("//table[@class='forceRecordLayout uiVirtualDataGrid--defaultuiVirtualDataGrid forceVirtualGrid resizable-cols']//tr"));
List<string> linkNamesList = new List<string>();
//Click the required link.
foreach(IWebElement element in req)
{
string linkName = element.text;
if(linkName == link)
{
element.click();
break;
}
}
}
{
//滚动到表格。
动作动作=新动作(驱动);
action.MoveToElement(driver.FindElement)(By.Id(“tableID”);
//获取列表中的元素
List req=驱动程序。findElements(按
.xpath(“//表[@class='forceRecordLayout uiVirtualDataGrid--defaultuiVirtualDataGrid forceVirtualGrid可调整大小的cols']//tr”);
List linkNamesList=新列表();
//单击所需的链接。
foreach(请求中的IWebElement元素)
{
字符串linkName=element.text;
if(linkName==link)
{
元素。单击();
打破
}
}
}
这应该行得通
谢谢
拉凯什·劳特这似乎对我有用:
WebElement table = wait.until(presenceOfElementLocated(By.tagName("tbody")));
int len = table.findElements(By.tagName("tr")).size();
for (int index = 0; index < len; index++) {
WebElement tr = table.findElements(By.tagName("tr")).get(index);
//save information in row
if (index == len - 1) {
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.scrollBy(0,250)");
len = table.findElements(By.tagName("tr")).size();
}
}
WebElement table=wait.until(存在元素定位(通过.tagName(“tbody”));
int len=table.findElements(按.tagName(“tr”)).size();
对于(int index=0;index
向下滚动时,循环的长度会发生变化,因此它会获取表中的所有行请尝试此处提供的选项。我想向下滚动页面。当页面向下滚动时,我想在列表中存储值,并从列表中单击表内的链接。当您一直滚动到页面底部时会发生什么情况?D整个表格是否加载或页面是否卸载以前的元素?我想你无法将我们链接到这方面的示例?谢谢Rakesh。我不想滚动到表格,表格数据在页面滚动时加载。我想在滚动操作加载数据后将数据存储在列表中。OP代码的第一行向下滚动到页面底部。