Table element not found

43 views
Skip to first unread message

Carlos Ramos

unread,
Jun 27, 2024, 3:15:29 AM (6 days ago) Jun 27
to Selenium Users
Hello . I am having problems locating a table element.


Error al contar los avisos: no such element: Unable to locate element: {"method":"xpath","selector":"//table[@id='lstAvisos']"}

My Html es .

   <div id="lstAvisos_shell">
                            <div class="table-responsive">
                                <script class="tabla-izfe-js"
                                    src="https://www9desa.sare.gipuzkoa.net/estaticos/baibot/js/plugins/wfi/tabla-baibot_1-8-5.min.js"></script>
                                <table id="lstAvisos"
                                    class="table table-bordered table-striped table-hover dataTable"
                                    style="margin-bottom: 1rem;" data-izfe-table="NONE"
                                    data-izfe-table-configured="true">
                                    <colgroup>
                                        <col style="width: 2%" hidden="">
                                        <col>
                                        <col>


And I have the POM page in Java, I have it like this

public class InicioPage extends BasePage {


By tabla_avisos = By.xpath("//table[@id='lstAvisos']");


public InicioPage(WebDriver driver) {
super(driver);
}

public int contarAvisos() {
        try {
            WebElement avisosTabla = this.driver.findElement(tabla_avisos);
            List<WebElement> filas = avisosTabla.findElements(By.tagName("//tr"));
           
            System.out.println("El webelement es :" + avisosTabla.getAttribute("outerHTML"));
             
           
           
            System.out.println("El número de filas es: " + filas.size());
            return filas.size();

thank you


Sir Jo

unread,
Jun 27, 2024, 8:16:31 AM (6 days ago) Jun 27
to Selenium Users

hola, que tal ??

can you provide more HTML code so we can try ??
however, you can try to find element by id (and not by xpath)

Un saludo
Sergio

SiKing

unread,
Jun 27, 2024, 2:33:27 PM (5 days ago) Jun 27
to Selenium Users
I don't see any kind of wait in your page object to determine if the page is finished loading.

Also, you are almost certainly going to have problems with this statement:
avisosTabla.findElements(By.tagName("//tr"));
When using xpath be aware that webdriver follows standard conventions: a search prefixed with "//" will search the entire document, not just the children of this current node. Use ".//" to limit your search to the children of this WebElement.
Reply all
Reply to author
Forward
0 new messages