在我得到8/9行的输出后,出现“陈旧元素引用:元素未附加到页面文档中”错误。我也尝试使用显式等待,但是经过几行后却给了我这个错误。我正在尝试从动态表中获取公司列表。
public void stockdetailsfromtable() throws InterruptedException, AWTException {
System.out.println("Dynamic table stock details" );
driver.get("https://economictimes.indiatimes.com/marketstats/pid-237,exchange-50,pageno-1,sortby-volume,sortorder-desc,ctype-MACD.cms");
Robot r = new Robot();
r.mouseWheel(5);
Thread.sleep(200);
driver.findElement(By.xpath("//a[contains(text(),'Equities')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'Live Stats')]")).click();
driver.findElement(By.xpath("//li[@class='level_1 active']//a[@id='e_ls_Gainers']")).click();
driver.findElement(By.xpath("//div[@class='period hidden']//button[contains(text(),'1W')]")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//button[@class='pg_num']")).click();
driver.findElement(By.xpath("//a[contains(text(),'100 rows')]")).click();
Thread.sleep(3000);
WebElement table = driver.findElement(By.xpath("//div[@id='dataDisplay']"));
WebElement row =table.findElement(By.xpath("//div[@class='dataList']"));
List<WebElement>companyname = row.findElements(By.xpath("//li[@class = 'w180']"));
int size= companyname.size();
System.out.println(size);
for (int i = 0; i<size;i++ )
{
Thread.sleep(2000);
String Cname =companyname.get(i).getText();
System.out.println(Cname);
}