Trying to print table element sequentially in console. Code given below please help:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class Softwaretestingo {
public static void main(String[] args) throws Exception {
//Webdrivermanager to open chromebrowser
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://softwaretestingo.blogspot.com/2020/09/static-table.html");
driver.findElements(By.xpath("//Table"));
List<WebElement> rows=driver.findElements(By.xpath("//Table//tr"));
System.out.println(rows.size());
List<WebElement> cols=driver.findElements(By.xpath("//Table//th"));
System.out.println(cols.size());
List<WebElement> rd = driver.findElements(By.xpath("//Table//td"));
System.out.println(rd.size());
//itrate throgh the table elements
for(WebElement e : cols)
{
System.out.println(e.getText());
}
for(int i = 1 ; i <= cols.size() ; i++)
{
List<WebElement> thiteration = driver.findElements(By.xpath("//Table//th"));
for(WebElement e2 : thiteration)
{
System.out.println(e2.getText());
}
List<WebElement> tditeration = driver.findElements(By.xpath("//Table//td"));
for(WebElement e1 : tditeration)
{
System.out.println(e1.getText());
}
Thread.sleep(3000);
}
}
}
Output as per the above code:
http://localhost:19529 for channel [id: 0xb0a056df, L:/127.0.0.1:64075 - R:localhost/127.0.0.1:19529]
Learn Selenium
19:06:07.566 [Forwarding getElementText on session b8964f2247db71d7a0f851f3441d3342 to remote] DEBUG org.asynchttpclient.netty.request.NettyRequestSender - Using pooled Channel '[id: 0xb0a056df, L:/127.0.0.1:64075 - R:localhost/127.0.0.1:19529]' for 'GET' to 'http://localhost:19529/session/b8964f2247db71d7a0f851f3441d3342/element/8ED067903D940894D08DF7C9EE6DC3EC_element_14/text'
19:06:07.566 [Forwarding getElementText on session b8964f2247db71d7a0f851f3441d3342 to remote] DEBUG org.asynchttpclient.netty.request.NettyRequestSender - Using open Channel [id: 0xb0a056df, L:/127.0.0.1:64075 - R:localhost/127.0.0.1:19529] for GET '/session/b8964f2247db71d7a0f851f3441d3342/element/8ED067903D940894D08DF7C9EE6DC3EC_element_14/text'
19:06:07.585 [AsyncHttpClient-1-2] DEBUG org.asynchttpclient.netty.handler.HttpHandler -
Request DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: EmptyByteBufBE)
GET /session/b8964f2247db71d7a0f851f3441d3342/element/8ED067903D940894D08DF7C9EE6DC3EC_element_14/text HTTP/1.1
User-Agent: selenium/4.9.1 (java windows)
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
host: localhost:19529
accept: */*
Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Length: 16
Content-Type: application/json; charset=utf-8
cache-control: no-cache
19:06:07.586 [AsyncHttpClient-1-2] DEBUG org.asynchttpclient.netty.channel.ChannelManager - Adding key: http://localhost:19529 for channel [id: 0xb0a056df, L:/127.0.0.1:64075 - R:localhost/127.0.0.1:19529]
Amit