0

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 !

7
  • Can u please share URL or paste your code in question. Commented Sep 27, 2017 at 18:09
  • @iamsankalp89 sorry but i can not insert url because it is from my college Commented Sep 27, 2017 at 18:12
  • i need only download text from one row Commented Sep 27, 2017 at 18:12
  • Actually in youe image I am unable to see complete HTML Commented Sep 27, 2017 at 18:12
  • but i can send HTML Commented Sep 27, 2017 at 18:19

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

4 Comments

@david try this
error when: String s = driver.findElement(By.xpath("//img[contains(@style,'vertical-align:middle)][contains(text(),'Rejestracja bezpo')]")).toString();
String s = driver.findElement(By.xpath("//img[contains(@style,'vertical‌​-align:middle)][cont‌​ains(text(),'Rejestr‌​acja bezpo')]")).getText(); try this
0

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);

5 Comments

wait i will try
you are amazing! its work. But if I know the value of the left column, can I know the right value? For example, the left column = "Status rejestracji przedmiotu::" and the right = "Studenci mog"
Wait i will try
String s = driver.findElement(By.xpath(".//*[@id='layout-c22a']/div/table[3]/tbody/tr[2]/td[2]")).getText(); System.out.println(s); try this
Thank you bro! I got the answer by code: String ss = driver.findElement(By.xpath("//table[3]/tbody/tr[9]/td[2]")).getText();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.