0

I am new to Selenium Python. I am using Selenium for logging into a website. So far I have successfully logged in and navigated to the page I want. In that page I have a table with id "Common". Inside the table body I have a no. of table rows. I need to get a particular the value "234" from the table. Below is the rough look of the HTML. I need the value "234" to be printed in the output window. I am using Python 2.7. Any help is much appreciated.

<div id="Common" class="x6w" theme="medium">
<div id="Common::content" class="x108" theme="medium">
    <div>
        <div id="pf12" class="x19" theme="medium">
            <table cellpadding="0" cellspacing="0" border="0" summary="" role="presentation" style="width: auto">
                <tbody>
                    <tr>
                        <td class="x4w" theme="medium" colspan="1">
                            <table cellpadding="0" cellspacing="0" border="0" width="100%" summary="" role="presentation">
                                <tbody>
                                    <tr><td style="width: 150px"></td><td></td></tr>
                                        <tr>....</tr>
                                        <tr>....</tr>
                                        <tr class="13" theme="medium" id="15"><td class="13" theme="medium"><label class="label-text" theme="medium">ID</label></td><td valign="top" style="padding-left:9px" class="xv" theme="medium">234</td></tr>
4
  • I think you should elaborate more. See stackoverflow.com/help/on-topic Commented Aug 13, 2020 at 1:29
  • @Ben I have edited my question, do you need anymore info? Commented Aug 13, 2020 at 2:37
  • Do you have any attempts of doing that? If yes, could you add those code snippets? Commented Aug 13, 2020 at 2:48
  • no @Ben I haven't tried that Commented Aug 13, 2020 at 3:46

3 Answers 3

1

there is a authorisation error, in the html code

please provide the link for the page[Complte]

I you want to know how to iterate through elements this code snippet from Github will help you

Sign up to request clarification or add additional context in comments.

Comments

0

Your problem seems related to locating an element. You can do research on relative xpath

Anyways, base on your html, here's the locator using xpath

targetElem = driver.find_element_by_xpath("//div[contains(@id,'Common')]//tbody/*[text()='ID']/parent::td/following-sibling::td") value = targetElem.text

Comments

0

For any webtable that you are accessing you should be able to extract the the td columns and for that you need to identify that way to make the unique locator like in the case above, you have text in between tags so you can xpath using javascript function "//*[text()='234]" otherwise the id attribute can be used to extract that element and using the "text" function you can get the text printed on console.

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.