Unable to locate a checkbox in a table (Selenium Java)

Viewed 48

I have been facing a problem for several days. Indeed I have several scenarios to test (Creation, edition, deletion) of an element in an array. The table contains this:

<iframe id="xFrame">

<div class="xddd" xpath="1">
    <form id="xinputForm" name="xname" method="POST" action="#" class="ggg">
          <table class="x-table border">
  <tbody>
    <tr>
        <th class="X1" ></th>
        <th class="X2" ></th>
        <th class="X3" ></th>
        <th class="X4" ></th>
    </tr>
    <tr value="{xvalueDynamic1}" id="{idDynamic1}" name="xName">
        <td  class="xell">
            <label class="plm-custom-control mr-1"><input type="checkbox" id="chk" name="chk" value="{ValueDynamic}"><span></span></label>
            <img src="./Images/Icons/ximgEmpty.gif" >&nbsp;
             </td>
        <td class="xell">
                     &nbsp;
                    <a href="javascript:customMethod('{HrefDYnamic1}','0','Edit');">CS1</a>
        </td>
        <td class="xell">
            &nbsp;Ceci est le premier CS</td>
        <td class="xell" >
                 &nbsp;Sep 07, 2022 &nbsp;
             </td>
    </tr>
    <tr value="{xvalueDynamic1}" id="{idDynamic2}" name="SelectCS">
        <td class="xell">
            <label class="classLabel"><input type="checkbox" id="dc" name="dc" value="{ValueDynamic}"><span></span></label>
            <img src="./Images/Icons/imgEx.gif">&nbsp;
            </td>
        <td class="xell">
                     &nbsp;
                    <a href="javascript:customMethod('{HrefDYnamic2}','0','Edit');">dfdf</a>
        </td>
        <td class="xell">
                &nbsp;dddddddddddddd
        </td>
        <td class="xell" ">
                 &nbsp;Sep 08, 2022&nbsp;
             </td>
    </tr>
            </tbody></table>
        </form>
    </div>
</iframe>

I want to check an element in the array to do some actions (editing, deleting etc) after its creation from selenium. I have no problem creating the element. However, I can't locate the element in the array. The painting is in 2 frames. I can access the frames but not the element Here is the code:

public EditElementPage clickOnButtonEdit() throws InterruptedException {
    
    Action.switchToFrameById(driver, "IdFrame1");   
    Action.switchToFrameById(driver, "IdFrame2");
    
    String xpathText = "//td/a[contains(text(),'CS1')]/preceding-sibling::td/label/following-sibling::input[@id='chk']";
    driver.findElement(By.xpath(xpathText)).click();

    Action.scrollByVisibilityOfElement(driver, iconEdit);
    //Action.fluentWait(iconEdit,10);
    Action.click(driver, iconEdit);
    Thread.sleep(2000);
    Action.click(driver, buttonEdit);
    return new EditElementPage ();
}`

Thank you for your help

0 Answers
Related