0

I am trying to access specific a <tr> element in an HTML Code.

The part of the code where the element is defined is shown as follows

<tr class='oddRow cellCont' OAArgs="OLMMV0-Walarus-Data-Maladie','" id='$PpyWorkPage$pPathologies$l1' data-test-id='202004251224080892667-R1' PL_INDEX = '1' >.

After the second line of the code below, I tried to declare the expressions tableRow.className() and tableRow.attr("class") which both returned "oddRow cellCont" of the type java.lang.String

But, I tried the following snipet which does not work since the condition in the loop returns false. I also tried the if condition using tableRow.attr("class") and oddRow, cellCont, oddRow , ... in all possible combinations.

I am definetely stuck; I need help please.

Elements tableRows  = field.getElementsByTag("tr");
for (Element tableRow : tableRows) {
    if (tableRow.className() == "oddRow cellCont")```
 

1 Answers1

0

I tried with str1.equals(str2) and it works.

  • That's right. https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java/513839#513839 Also your class checking won't work if classes have different order. The best check would be: `if (tableRow.hasClass("oddRow") && tableRow.hasClass("cellCont"))` – Krystian G Apr 19 '21 at 23:56