lundi 21 décembre 2015

find a checkbox from a tr tag and select it in Selenium(java)

I used the following code to retrieve the row that I want to select in selenium:

WebElement row = driver.findElement(By.xpath("//tr[contains(.,'prod1')]"));

As a result, I get the following row:

<th width="18px">
                <input class="selectedProducts" id="checkbox-37640" onclick="markedProductsHandler.toggleMarkProduct(this,37640)" type="checkbox">
            </th>


            <th style="white-space:nowrap; width:573px;" align="left">

<a class="maxTextSize" style="width:530px" href="product.html?id=37640&amp;rm7zz5c=ZBOeBCOAs">aa prod1</a>
            </th>

            <th style="white-space:nowrap;" align="right" width="140px">

                    <a href="product-edit.html?id=37640&amp;rm7zz5c=ZBOeBCOAs"><img src="_images/icons/pencil.png?rm7zz5c=ZBOeBCOAs" title="Edit"></a> &nbsp;


                        <input name="favoriteid" class="favoriteAction" value="37640" type="hidden">
                        <input name="favoriteaction" class="favoriteAction" value="add" type="hidden">
                        <a href="javascript:" onclick="onFavoriteAction(this)">
                            <img src="_images/icons/star_grey.png?rm7zz5c=ZBOeBCOAs" alt="Watch product" title="Watch product">
                        </a> &nbsp;

        <form action="product-pdf.html?rm7zz5c=ZBOeBCOAs" method="post">
            <input name="export" value="pdf" type="hidden">
            <input name="id" value="37640" type="hidden">
            <a href="javascript:" onclick="javascript: $(this).parent().submit();"><img src="_images/icons/page_white_acrobat.png?rm7zz5c=ZBOeBCOAs" title="Download as PDF"></a> &nbsp;
        </form>
            </th>

Now I would like to select the checkbox:

row.findElement(By.xpath("//input[@type='checkbox']")).click();

but I get the following error:

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

Can anybody help me? Thanks.

Aucun commentaire:

Enregistrer un commentaire