org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: not able to locate the element inside table tag

Issue

I was trying to locate the element which is present inside the table tag
But iam getting the error

"org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@id=’divTable’]/child::div/child::div/child::table/child::tbody/child::tr/child::td2/input"}
(Session info: chrome=103.0.5060.114)"

Here is my code….

@Test (priority=8)
public void autogenerate() throws InterruptedException
{
    driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='axpiframe']")));
    WebElement autogenerate= driver.findElement(By.xpath("//body/div[@id='dvlayout']/div[@id='pagebdy']/div[@id='heightframe']/div[@id='wBdr']/div[@id='myModal']/div[1]/div[1]/div[2]/div[1]/ul[1]/li[9]/a[1]"));
    click(driver, autogenerate, 20);
    WebElement fieldname= driver.findElement(By.xpath("//input[@id='name000F1']"));
    sendkeys(driver, fieldname, 20, "autotime");
    WebElement fieldcaption= driver.findElement(By.xpath("//input[@id='caption000F1']"));
    click(driver, fieldcaption, 20);
    WebElement defsequence= driver.findElement(By.xpath("//input[@id='Def_Sequence000F2']"));
    click(driver, defsequence, 20);
    WebElement icon= driver.findElement(By.xpath("//body/div[@id='dvlayout']/div[@id='pagebdy']/div[@id='heightframe']/div[@id='wBdr']/div[@id='wbdrHtml']/div[@id='DivFrame2']/div[@id='divDc2']/div[@id='randomID_212']/div[@id='dvDef_Sequence']/div[2]/div[1]/i[1]"));
    click(driver, icon, 20);
    Thread.sleep(5000);
    
    
    WebElement prefix= driver.findElement(By.xpath("//div[@id='divTable']/child::div/child::div/child::table/child::tbody/child::tr/child::td[2]/input"));
    sendkeys(driver, prefix, 20, "AM");

}

Here is HTML….

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta charset="utf-8" /><meta name="description" content="Table" /><meta name="keywords" content="Agile Cloud, Axpert,HMS,BIZAPP,ERP" /><meta name="author" content="Agile Labs" /><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>
    Table
</title><link href="../Css/thirdparty/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet" type="text/css" /><link href="../ThirdParty/gridstack.js-0.3.0/dist/gridstack.css" rel="stylesheet" type="text/css" /><link href="../Css/thirdparty/jquery-ui/1.12.1/jquery-ui.min.css" rel="stylesheet" type="text/css" /><link href="../Css/thirdparty/jquery-ui/1.12.1/jquery-ui.structure.min.css" rel="stylesheet" type="text/css" /><link href="../Css/thirdparty/jquery-ui/1.12.1/jquery-ui.theme.min.css" rel="stylesheet" type="text/css" /><link href="../ThirdParty/jquery-confirm-master/jquery-confirm.min.css" rel="stylesheet" type="text/css" /><link href="../ThirdParty/DataTables-1.10.13/media/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css" /><link href="../Css/Icons/icon.css" rel="stylesheet" type="text/css" /><link href="../Css/thirdparty/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" /><link href="../ThirdParty/codemirror/codemirror.css" rel="stylesheet" type="text/css" /><link href="../Css/jquery-ui-timepicker-addon.min.css" rel="stylesheet" type="text/css" /><link href="../Js/jquery.timeentry.package/jquery.timeentry.css" rel="stylesheet" type="text/css" /><link href="../Css/globalStyles.min.css?v=35" rel="stylesheet" type="text/css" /><link href="../Css/wizardComp.min.css?v=17" rel="stylesheet" type="text/css" /><link href="../css/ExportNew.min.css?v=32" rel="stylesheet" type="text/css" /><link href="../Css/import.min.css?v=30" rel="stylesheet" type="text/css" /><link href="../Css/responsibilties.min.css?v=10" rel="stylesheet" type="text/css" /><link href="../Css/propSheet.min.css?v=3" rel="stylesheet" type="text/css" /><link href="../Css/msgBoxLight.css" rel="stylesheet" type="text/css" /><link href="../Css/tstructNewUi.min.css?v=59" rel="stylesheet" type="text/css" /><link href="../Css/animate.min.css" rel="stylesheet" type="text/css" /><link href="../ThirdParty/bootstrap-tokenfield/dist/css/bootstrap-tokenfield.min.css" rel="stylesheet" type="text/css" /><link href="../newPopups/Remodal/remodal-default-theme.min.css" rel="stylesheet" type="text/css" /><link href="../newPopups/Remodal/remodal.min.css" rel="stylesheet" type="text/css" /><link href="../Css/axpertPopup.min.css?v=22" rel="stylesheet" type="text/css" />
    <script>
        if (!('from' in Array)) {
            // IE 11: Load Browser Polyfill
            document.write('<script src="../Js/polyfill.min.js"><\/script>');
        }
    </script>
    <script type="text/javascript">
        var FetchPickListRows = 1000;
    </script>
    <script src="../Js/thirdparty/jquery/3.1.1/jquery.min.js"></script>
    <script src="../ThirdParty/DataTables-1.10.13/media/js/jquery.dataTables.min.js"></script>
    <script src="../ThirdParty/DataTables-1.10.13/media/js/dataTables.bootstrap.min.js"></script>
    <script src="../Js/jquery.browser.min.js"></script>
    <script src="../Js/printjs.min.js"></script>
    <script src="../ThirdParty/jquery-confirm-master/jquery-confirm.min.js"></script>
    <script src="../Js/noConflict.min.js"></script>
    <script type="text/javascript" src="../Js/iFrameHandler.min.js"></script>
    <script src="../Js/propSheet.min.js"></script>
    <script src="../Js/jquery.timeentry.package/jquery.timeentry.min.js"></script>
    <script src="../Js/alerts.min.js?v=28"></script>
    <script src="../Js/jQueryUi/jquery.tablesorter.min.js"></script>
    <script src="../ThirdParty/bootstrap-tokenfield/dist/bootstrap-tokenfield.min.js"></script>
    <script src="../Js/common.min.js?v=85"></script>
    <script src="../Js/ckeditor/ckeditor.js?v=1"></script>
    <script src="../Js/ckRtf.js"></script>
    <script src="../Js/JDate.min.js"></script>
    <script src="../Js/thirdparty/bootstrap/3.3.6/bootstrap.min.js"></script>
    <script src="../Js/thirdparty/jquery-ui/jquery-ui-autoCom/jquery-ui-autoCom.min.js"></script>
    <script src="../Js/jquery-ui-timepicker-addon.min.js"></script>
    <script src="../ThirdParty/lodash.min.js"></script>
    <script src="../ThirdParty/gridstack.js-0.3.0/dist/gridstack.js"></script>
    <script src="../ThirdParty/gridstack.js-0.3.0/dist/gridstack.jQueryUI.js"></script>
    <script src="../Js/jquery.msgBox.min.js"></script>
    <script src="../Js/jQueryUi/jquery.scrollabletab.min.js"></script>
    <script src="../Js/tstructvars.min.js?v=52"></script>
    <script src="../Js/md5.min.js"></script>
    <script src="../Js/adjustwindow.js"></script>
    <script src="../Js/wizardComp.js"></script>
    <script src="../Js/tstruct.min.js?v=383"></script>
    <script src="../Js/util.min.js"></script>
    <script src="../Js/tstruct-pdf.min.js"></script>
    <script src="../newPopups/Remodal/remodal.min.js"></script>
    <script src="../newPopups/axpertPopup.min.js?v=45"></script>
    <script src="../Js/handlebars.min.js?v=1"></script>
    <script src="../Js/tstTable.min.js?v=9"></script>
</head>
<body>
    <form name="form1" method="post" action="./tsttable.aspx?fldId=Def_Sequence000F2" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="3/epi2NOzZ4VmPo7Vmb+TxMGr70gGKys52QAMmeXvG5Lm3qOhrp7iFXHzQfiwsoUdicOkkwYT2rQ2QwYZWzysVJHmx3z88zoVTV22f99lx4=" />
</div>

<div>

    <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="7F438B0E" />
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="pZzJrDUxojFaoW1Xwo0BH7CLYZ2J12wPy/QjMK/JiLqwgeSvxBXWAXBmmIiK8LOyUv9Im74lsN5ecTx48/KdfR2puWHi3mg5Z9FaulZsR1nEfrwhpsISz3BpohI5R2+u" />
</div>
        <div id="divTable">
        </div>
        <input type="hidden" name="hdnfieldId" id="hdnfieldId" value="Def_Sequence000F2" />
    </form>
</body>
</html>

Here is page source…..

PAGE SOURCE IMAGE

ERROR IN ECLIPSE

Solution

We can see there is one frame before the element so first switch to frame and then Use below xpath for table value input

driver.switchTo().frame("iframeDefineSequence");
WebElement prefix= driver.findElement(By.xpath("//input[@name='prefixtxt']"));

Answered By – Ketan Pardeshi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published