I'm trying to get "title" attribute value and save it in csv file from element below:
<img src="images/i.png" title="Uwagi: łacina, nieczytelne
Data urodzenia: 25.02.1808 r.">
Whole html here.
I've got this attribute value using xpath below (it works):
SelenideElement uwagi = $(By.xpath("//div[@id='table_b_wrapper']//table[@id='table_b']//tbody//tr[1]//img[contains(@title,'Uwagi')]"));
//tr[1] is just a one example from this table. xpath is ok
Then I've tried to put it into my csv file with:
writer.append(uwagi+";"); //using ; as separator
Problem is that this value "Uwagi: łacina, nieczytelne Data urodzenia: 25.02.1808 r."
It's divided into 2 parts and they are saved as separate cells, like here
I need all this value in one cell (i.e. J1731 and A1732 values should be as 1 cell).
What's strange when I did System.out.println(uwagi.getAttribute("title"));
only 2nd part of attribute value (Data urodzenia: 25.02.1808 r.) was displayed in console.
How can I save this title attribute value as one cell in csv?
Regards Tomes
I've found solution. I've changed:
FileWriter writer = new FileWriter(pathString, Charset.forName("Cp1250"));
to
CsvWriter writer = new CsvWriter(pathString, ';', Charset.forName("Cp1250"));
using also:
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
Based on the info from: link
Then I've changed writer.apend to writer.write.
Other is the same:
...
SelenideElement xxx = $x("//img[contains(@title,'Uwagi')]");
String str = xxx.getAttribute("title");
writer.write(str);
...
Result: picture
Regards Tomes