【发布时间】:2018-03-08 07:29:33
【问题描述】:
我有一个列表,我收集了一个不断变化的股票价格列表
列出 listOfLastPrice1;
我知道这个列表不是恒定的,因为股票的价格不是恒定的。这意味着如果我现在打印它,并在 5 分钟内再次打印它,值会改变。为什么?因为这是一个直接连接到 DOM 的 WebElement 列表。
我创建了第二个列表
ArrayList listCopyLastPrice1 = new ArrayList();
我想将 WebElement 列表中的所有值复制到字符串列表中。 我该怎么做?
我尝试了几次,但都没有成功
package TestMain;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import PageObjects.Editions;
public class Test {
public void getList(WebDriver driver) {
driver.get("https:www.investing.com/Markets");
List <WebElement> listOfLastPrice1;
listOfLastPrice1= driver.findElements(By.cssSelector("[data-column-name='last'][class*='pid']"));
ArrayList<String> listCopyLastPrice1 = new ArrayList<String>();
//..........
}
}
【问题讨论】: