0

I don't understand why x-path doesn't working in table. I'm trying to iter table from the website I found xpath but Eclipse told me:

"Unable to find element with xpath".

Should I find xpath in tables another way?

Website URL: https://www.oferty.net/mieszkania/szukaj?ps%5Blocation%5D%5Btype%5D=1&ps%5Btype%5D=1&ps%5Btransaction%5D=1&ps%5Blocation%5D%5Btext%5D=dolno%C5%9Bl%C4%85skie

I try to read one offer for example:

String urlwyniki ="https://www.oferty.net/mieszkania/szukaj?ps%5Blocation%5D%5Btype%5D=1&ps%5Btype%5D=1&ps%5Btransaction%5D=1&ps%5Blocation%5D%5Btext%5D=dolno%C5%9Bl%C4%85skie";
driver.get(urlwyniki);
String xpathResult = "//html/body/div[2]/div[4]/div[2]/div[2]/div/div[2]/div[5]/table/tbody/tr[5]/td";
String sCellValue = driver.findElement(By.xpath(xpathResult)).getText();
System.out.print(sCellValue);

What did I do wrong?

4
  • try with x-path '//tbody/tr/td' Commented Jan 12, 2018 at 11:21
  • Could You wrote whole xpath as You think. I have tried several methods by classname: Commented Jan 12, 2018 at 11:54
  • Could You wrote whole xpath as You think. I have tried several methods by classname: table class "properties". If I use it I got the list of all offers. But when I want to iterate it eclipse write Number of rows in webtable = 0. Commented Jan 12, 2018 at 12:09
  • Which table? Which text ? Commented Jan 12, 2018 at 16:13

1 Answer 1

1

Find the below code to iterate all cell value in the table. It may help you.

String urlwyniki ="https://www.oferty.net/mieszkania/szukaj?ps%5Blocation%5D%5Btype%5D=1&ps%5Btype%5D=1&ps%5Btransaction%5D=1&ps%5Blocation%5D%5Btext%5D=dolno%C5%9Bl%C4%85skie";
driver.get(urlwyniki);
String xpathResult = "//table/tbody/tr/td";
List<WebElement> rows = driver.findElements(By.xpath(xpathResult));
List<WebElement> cols=new ArrayList<WebElement>();
for(int i=0;i<rows.size();i++){
    System.out.print("Row value: "+i);
    cols=rows.get(i).findElements(By.tagName("td"));
    for(WebElement col:cols)
        System.out.print("cell value "+col.getText());
} 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You Very Much

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.