David
David

Reputation: 5

WebDriver get text from table

I use WebDriver and ChromeDriver. How i can fetch text from second table?

I have two tables. 1: click to see photo

2: click to see photo

So, When i try download data from second table i download from first :/

    WebElement baseTable = driver.findElement(By.className("grey"));
    List<WebElement> tableRows = baseTable.findElements(By.tagName("tr"));
    JOptionPane.showMessageDialog(null, tableRows.get(1).getText());

Thank you for your help !

Upvotes: 0

Views: 2034

Answers (2)

iamsankalp89
iamsankalp89

Reputation: 4739

You can use xpath line this for this 'Actualny tryb'

//td[contains(@class,'strong'][contains(text(),'Actualny tryb')]

for this Rejestracja

//img[contains(@style,'vertical-align:middle')][contains(text(),'Rejestracja bezpo')]

Try this code, I don't know JOptionPane:

driver.get("https://www.usosweb.uj.edu.pl/kontroler.php?_action=katalog2/przedmioty/rejestracjaNaPrzedmiotCyklu&prz_kod=WOZ.PLD-3SDHTTP&cdyd_kod=17%2F18&callback=g_21a73193");

String s = driver.findElement(By.xpath("//td[contains(text(),'Status rejestracji przedmiotu')]")).getText();
System.out.println(s);
JOptionPane.showMessageDialog(null, s);

Upvotes: 1

David
David

Reputation: 5

will someone try? You need download selenium jar from: http://selenium-release.storage.googleapis.com/3.5/selenium-server-standalone-3.5.3.jar Download chromedriver: https://chromedriver.storage.googleapis.com/2.32/chromedriver_win32.zip Import jar file and copy code:

   System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.get("https://www.usosweb.uj.edu.pl/kontroler.php?_action=katalog2/przedmioty/rejestracjaNaPrzedmiotCyklu&prz_kod=WOZ.PLD-3SDHTTP&cdyd_kod=17%2F18&callback=g_21a73193");
    Wait();
    String s = driver.findElement(By.xpath("//img[contains(@style,'vertical‌​‌​-align:middle)][co‌​nt‌​ains(text(),'Rej‌​estr‌​acja bezpo')]")).getText();
    JOptionPane.showMessageDialog(null, s);

Upvotes: 0

Related Questions