0

I would like to get the text of a cell in a table of a html with python and selenium, but I get this error:

Message: no such element: Unable to locate element: {"method":"name","selector":"ctl00_ContentPlaceHolder1_ctl02_tblHistorico"}

The html:

<div id="ctl00_ContentPlaceHolder1_ctl02_divTabelaHistorico">
    <br />
    <table id="ctl00_ContentPlaceHolder1_ctl02_tblHistorico" class="tablefq" width="100%" border="0" cellspacing="1" cellpadding="0">
        <tr>
            <td id="ctl00_ContentPlaceHolder1_ctl02_tdTitulo" class="tituloTV" height="20" colspan="6">XX</td>
        </tr>
        <tr>
            <td class="TDTVHeader" width="4%"><a id='aSinalMain' class='sinal hand' onclick='aSinalMain_onClick(this)'>[+]</a></td>
            <td class="TDTVHeader" colspan="1">XXXnbsp;</td>
            <td class="TDTVHeader" colspan="1">XXXbsp;</td>
            <td class="TDTVHeader" colspan="1">XXXsp;</td>
            <td class="TDTVHeader" colspan="1">XXX</td>
            <td class="TDTVHeader" colspan="1">XXX&nbsp;</td>
        </tr>
        <tr>
            <td class="TDFQ" colspan="1"><a id='aSinal' class='sinal hand'>[+]</a></td>
            <td class="TDFQ" colspan="1">XXX</td>
            <td class="TDFQ" colspan="1">XXX</td>
            <td class="TDFQ" colspan="1">XX</td>
            <td class="TDFQ" colspan="1">XX</td>
            <td class="TDFQ" colspan="1">XX</td>
        </tr>
        <tr style="display:none;">
            <td class="TDFQ historico" colspan="6"><div class=scroll>I WANT HERE HERE HERE</div></td>
        </tr>
        <tr>
            <td class="TDFQ" colspan="1"><a id='aSinal' class='sinal hand'>[+]</a></td>
            <td class="TDFQ" colspan="1">XXXp;</td>
            <td class="TDFQ" colspan="1">XXX&nbsp;</td>
            <td class="TDFQ" colspan="1">XXXT;</td>
            <td class="TDFQ" colspan="1">XXX</td>
            <td class="TDFQ" colspan="1">XXX&nbsp;</td>
        </tr>
    </table>
    </div>  

Python code:

text = driver.find_element_by_name('ctl00_ContentPlaceHolder1_ctl02_tblHistorico')

3 Answers 3

1

According to your description, you are looking for "id" no for "name", so use the method:

table = driver.find_element_by_id('ctl00_ContentPlaceHolder1_ctl02_tblHistorico')

This would give you an element with the entire table.

If you know something else about the cell that you want, you could find for that specific element.

https://selenium-python.readthedocs.io/locating-elements.html

For example, to get the text that you marked in your post you can use this because there is only one tag with that class name:

div = driver.find_element_by_class_name('scroll')
text = div.text
Sign up to request clarification or add additional context in comments.

Comments

0

Please try the below code.Let me know if that helps.You need JavaScripts executor to get the text of hiddden field.

eletext=driver.execute_script("return arguments[0].innerHTML;",driver.find_element_by_xpath("//div[@class='scroll']"))
print(eletext)

Hope this help you.

4 Comments

The loop brings only the tags tr.. Do not bring the tag tr <tr style="display:none;"> <tr style="display:none;"> <td class="TDFQ historico" colspan="6"><div class=scroll>I WANT HERE HERE HERE</div></td>
I have updated my answer to get the value You wanted.Please accept my answer if it helps.
Thank you Kajal Kundu This code solved my problem...I was trying to get this text during a long time.Thank you
Can you please accept my answer by click on accept button on my code message.
0

What you want is to get the desired element by a CSS selector.

This is the method you want to use.

The right CSS selector expression would be the following string.

#ctl00_ContentPlaceHolder1_ctl02_tblHistorico.TDFQ historico

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.