0

I am trying to click on a link which is inside a table using selenium. This is my code for it:

element = WebDriverWait(driver, 30).until(

    EC.presence_of_element_located((By.XPATH, "/html/body/table/tbody/tr/td/table/tbody/tr[11]/td[3]/a"))
)

element.click()

This is the anchor tag I am trying to click on

I have tried using the other methods to locate the element such as by link text, CSS selector and class name but nothing seems to work. It doesn't seem to be able to locate the anchor element.

By link text: By.LINK_TEXT, "Booking"

By CSS selector: By.CSS_SELECTOR, "body > table > tbody > tr > td > table > tbody > tr:nth-child(11) > td:nth-child(3) > a"

By class name: By.CLASS_NAME, "sidelinkbold"

This is how the website looks like

Full page

<html data-darkreader-mode="dynamic" data-darkreader-scheme="dark"><head><style class="darkreader darkreader--fallback" media="screen"></style><style class="darkreader darkreader--text" media="screen"></style><style class="darkreader darkreader--invert" media="screen">.jfk-bubble.gtx-bubble, .captcheck_answer_label > input + img, span#closed_text > img[src^="https://www.gstatic.com/images/branding/googlelogo"], span[data-href^="https://www.hcaptcha.com/"] > #icon, #bit-notification-bar-iframe, embed[type="application/pdf"] {
    filter: invert(100%) hue-rotate(180deg) brightness(150%) contrast(60%) !important;
}</style><style class="darkreader darkreader--inline" media="screen">[data-darkreader-inline-bgcolor] {
  background-color: var(--darkreader-inline-bgcolor) !important;
}
[data-darkreader-inline-bgimage] {
  background-image: var(--darkreader-inline-bgimage) !important;
}
[data-darkreader-inline-border] {
  border-color: var(--darkreader-inline-border) !important;
}
[data-darkreader-inline-border-bottom] {
  border-bottom-color: var(--darkreader-inline-border-bottom) !important;
}
[data-darkreader-inline-border-left] {
  border-left-color: var(--darkreader-inline-border-left) !important;
}
[data-darkreader-inline-border-right] {
  border-right-color: var(--darkreader-inline-border-right) !important;
}
[data-darkreader-inline-border-top] {
  border-top-color: var(--darkreader-inline-border-top) !important;
}
[data-darkreader-inline-boxshadow] {
  box-shadow: var(--darkreader-inline-boxshadow) !important;
}
[data-darkreader-inline-color] {
  color: var(--darkreader-inline-color) !important;
}
[data-darkreader-inline-fill] {
  fill: var(--darkreader-inline-fill) !important;
}
[data-darkreader-inline-stroke] {
  stroke: var(--darkreader-inline-stroke) !important;
}
[data-darkreader-inline-outline] {
  outline-color: var(--darkreader-inline-outline) !important;
}
[data-darkreader-inline-stopcolor] {
  stop-color: var(--darkreader-inline-stopcolor) !important;
}</style><style class="darkreader darkreader--variables" media="screen">:root {
   --darkreader-neutral-background: #3a3c3d;
   --darkreader-neutral-text: #ffffff;
   --darkreader-selection-background: #2677d9;
   --darkreader-selection-text: #ffffff;
}</style><style class="darkreader darkreader--root-vars" media="screen"></style><script class="darkreader darkreader--proxy">(function injectProxy() {
        document.dispatchEvent(
            new CustomEvent("__darkreader__inlineScriptsAllowed")
        );
        const addRuleDescriptor = Object.getOwnPropertyDescriptor(
            CSSStyleSheet.prototype,
            "addRule"
        );
        const insertRuleDescriptor = Object.getOwnPropertyDescriptor(
            CSSStyleSheet.prototype,
            "insertRule"
        );
        const deleteRuleDescriptor = Object.getOwnPropertyDescriptor(
            CSSStyleSheet.prototype,
            "deleteRule"
        );
        const removeRuleDescriptor = Object.getOwnPropertyDescriptor(
            CSSStyleSheet.prototype,
            "removeRule"
        );
        const shouldWrapDocStyleSheets =
            location.hostname.endsWith("pushbullet.com") ||
            location.hostname.endsWith("ilsole24ore.com") ||
            location.hostname.endsWith("allegro.pl");
        const documentStyleSheetsDescriptor = shouldWrapDocStyleSheets
            ? Object.getOwnPropertyDescriptor(Document.prototype, "styleSheets")
            : null;
        const cleanUp = () => {
            Object.defineProperty(
                CSSStyleSheet.prototype,
                "addRule",
                addRuleDescriptor
            );
            Object.defineProperty(
                CSSStyleSheet.prototype,
                "insertRule",
                insertRuleDescriptor
            );
            Object.defineProperty(
                CSSStyleSheet.prototype,
                "deleteRule",
                deleteRuleDescriptor
            );
            Object.defineProperty(
                CSSStyleSheet.prototype,
                "removeRule",
                removeRuleDescriptor
            );
            document.removeEventListener("__darkreader__cleanUp", cleanUp);
            document.removeEventListener(
                "__darkreader__addUndefinedResolver",
                addUndefinedResolver
            );
            if (shouldWrapDocStyleSheets) {
                Object.defineProperty(
                    Document.prototype,
                    "styleSheets",
                    documentStyleSheetsDescriptor
                );
            }
        };
        const addUndefinedResolver = (e) => {
            customElements.whenDefined(e.detail.tag).then(() => {
                document.dispatchEvent(
                    new CustomEvent("__darkreader__isDefined", {
                        detail: {tag: e.detail.tag}
                    })
                );
            });
        };
        document.addEventListener("__darkreader__cleanUp", cleanUp);
        document.addEventListener(
            "__darkreader__addUndefinedResolver",
            addUndefinedResolver
        );
        const updateSheetEvent = new Event("__darkreader__updateSheet");
        function proxyAddRule(selector, style, index) {
            addRuleDescriptor.value.call(this, selector, style, index);
            if (
                this.ownerNode &&
                !this.ownerNode.classList.contains("darkreader")
            ) {
                this.ownerNode.dispatchEvent(updateSheetEvent);
            }
            return -1;
        }
        function proxyInsertRule(rule, index) {
            const returnValue = insertRuleDescriptor.value.call(
                this,
                rule,
                index
            );
            if (
                this.ownerNode &&
                !this.ownerNode.classList.contains("darkreader")
            ) {
                this.ownerNode.dispatchEvent(updateSheetEvent);
            }
            return returnValue;
        }
        function proxyDeleteRule(index) {
            deleteRuleDescriptor.value.call(this, index);
            if (
                this.ownerNode &&
                !this.ownerNode.classList.contains("darkreader")
            ) {
                this.ownerNode.dispatchEvent(updateSheetEvent);
            }
        }
        function proxyRemoveRule(index) {
            removeRuleDescriptor.value.call(this, index);
            if (
                this.ownerNode &&
                !this.ownerNode.classList.contains("darkreader")
            ) {
                this.ownerNode.dispatchEvent(updateSheetEvent);
            }
        }
        function proxyDocumentStyleSheets() {
            const docSheets = documentStyleSheetsDescriptor.get.call(this);
            const filtered = [...docSheets].filter((styleSheet) => {
                return !styleSheet.ownerNode.classList.contains("darkreader");
            });
            return Object.setPrototypeOf(filtered, StyleSheetList.prototype);
        }
        Object.defineProperty(
            CSSStyleSheet.prototype,
            "addRule",
            Object.assign({}, addRuleDescriptor, {value: proxyAddRule})
        );
        Object.defineProperty(
            CSSStyleSheet.prototype,
            "insertRule",
            Object.assign({}, insertRuleDescriptor, {value: proxyInsertRule})
        );
        Object.defineProperty(
            CSSStyleSheet.prototype,
            "deleteRule",
            Object.assign({}, deleteRuleDescriptor, {value: proxyDeleteRule})
        );
        Object.defineProperty(
            CSSStyleSheet.prototype,
            "removeRule",
            Object.assign({}, removeRuleDescriptor, {value: proxyRemoveRule})
        );
        if (shouldWrapDocStyleSheets) {
            Object.defineProperty(
                Document.prototype,
                "styleSheets",
                Object.assign({}, documentStyleSheetsDescriptor, {
                    get: proxyDocumentStyleSheets
                })
            );
        }
    })()</script><style class="darkreader darkreader--user-agent" media="screen">input, textarea, select, button {
    background-color: #3f4243;
}
html, body, input, textarea, select, button {
    border-color: #9f9789;
    color: #ffffff;
}
a {
    color: #5cbeff;
}
table {
    border-color: #7e8689;
}
::placeholder {
    color: #e1dacf;
}
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
    background-color: #7f8626 !important;
    color: #ffffff !important;
}
::-webkit-scrollbar {
    background-color: #484b4c;
    color: #dad2c7;
}
::-webkit-scrollbar-thumb {
    background-color: #6f7477;
}
::-webkit-scrollbar-thumb:hover {
    background-color: #82898d;
}
::-webkit-scrollbar-thumb:active {
    background-color: #72787b;
}
::-webkit-scrollbar-corner {
    background-color: #3f4243;
}
::selection {
    background-color: #2677d9 !important;
    color: #ffffff !important;
}
::-moz-selection {
    background-color: #2677d9 !important;
    color: #ffffff !important;
}</style><script language="JavaScript">
// Create account variable
var var_acct;
// --

var_acct = 925479
 //document.write(var_acct);
 
</script>

 
<title>BBDC: Side Navigation</title> 
<link rel="stylesheet" href="../css/content.css" type="text/css"><style class="darkreader darkreader--sync" media="screen"></style>
<script language="javascript" src="../admin/inc-script/common.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta name="darkreader" content="b042933e61e724920d01151a5694719f"><style class="darkreader darkreader--override" media="screen">.vimvixen-hint {
    background-color: #a87e0f !important;
    border-color: #ffdf3a !important;
    color: #fffff8 !important;
}
::placeholder {
    opacity: 0.5 !important;
}
a[href="https://coinmarketcap.com/"] > svg[width="94"][height="16"] > path {
    fill: var(--darkreader-neutral-text) !important;
}
#edge-translate-panel-body {
    color: var(--darkreader-neutral-text) !important;
}</style></head>

<body class="sidetxtbold" marginwidth="5" marginheight="5" topmargin="5" leftmargin="5" background="">
<!-- Begin Enrolment Process --> 
<table width="150" border="0" cellspacing="0" cellpadding="0" bgcolor="#CCCCCC" data-darkreader-inline-bgcolor="" style="--darkreader-inline-bgcolor:#5e6264;">
    <tbody><tr><!--<td><img src="../image/invis.gif" width="5" height="1"></td>-->
    <td width="100%">
        <table class="sidetxtbold" width="100%" border="0" cellspacing="0" cellpadding="0">     
        <tbody><tr valign="top">
            <td></td>   
        </tr>
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
                <td colspan="2"><a href="../b-default.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Home'; return true" onmouseout="window.status=' '; return true">Home</a></td>
        </tr>
         
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-3c-branchNvenues.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Branch and Venues'; return true" onmouseout="window.status=' '; return true">Branch and Venues</a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
       
       <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
                <td class="sidetxtbold" colspan="2"><a href="../a-PayNow.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Home'; return true" onmouseout="window.status=' '; return true"><font color="red" data-darkreader-inline-color="" style="--darkreader-inline-color:#ff4242;">PayNow Topup</font></a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
       
        
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-ShowPPL.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='PPL Book'; return true" onmouseout="window.status=' '; return true">Practical Training HandBook</a></td>
        </tr>
        
            <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
            <!--
            <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
                <td class="sidetxtbold" colspan="2"><A HREF="../b-updatePDLExpiryDate.asp" class="sidelinkbold" target="mainFrame" onMouseOver=" window.status='Home'; return true" onMouseOut="window.status=' '; return true">PDL Expiry Date Update</a></td>
        </tr>
    
        
    
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        -->
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td class="sidetxtbold" colspan="2" onmouseover="window.status='Practical Training'" onmouseout="window.status=' '">TP Simulator</td>
        </tr>
            
            <tr valign="top">
                <td>&nbsp;</td>
            <td><img src="../image/site/icn-arrow-blue.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-selectTPDSModule.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Booking'; return true" onmouseout="window.status=' '; return true">Booking</a></td>
        </tr>
    
    <tr valign="top">
                <td>&nbsp;</td>
            <td><img src="../image/site/icn-arrow-blue.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-tpds-LessonCancel.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Booking'; return true" onmouseout="window.status=' '; return true">Cancel</a></td>
        </tr>
        
            <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        <!-- ended 05112009 -->
        

        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td class="sidetxtbold" colspan="2" onmouseover="window.status='Theory Training'" onmouseout="window.status=' '">Theory Training</td>
        </tr>
        
            
        <tr valign="top">
            <td>&nbsp;</td>
            <td><img src="../image/site/icn-arrow-blue.gif">&nbsp;</td>
    
            
                <td width="100%"><a href="../b-selectTheory.asp?action=book" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Theory Training Booking'; return true" onmouseout="window.status=' '; return true">Booking</a></td>
            

        </tr>
        
        
        <tr valign="top">
            <td>&nbsp;</td>
            <td><img src="../image/site/icn-arrow-blue.gif">&nbsp;</td>
            <td class="sidetxtbold" width="100%"><a href="../b-selectTheory.asp?action=cancel" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Theory Training Cancel'; return true" onmouseout="window.status=' '; return true">Cancel</a></td>
        </tr>
        <tr>
            <td class="sidetxtbold" colspan="3">&nbsp;</td>
        </tr>
        
       
        
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td class="sidetxtbold" colspan="2" onmouseover="window.status='Practical Test'" onmouseout="window.status=' '">Practical Test</td>
        </tr>
        
            
        <tr valign="top">
            <td>&nbsp;</td>
            <td><img src="../image/site/icn-arrow-blue.gif">&nbsp;</td>
            <!--
            <td width="100%"><a href="../b-3c-practicalTestBooking.asp?+3" class="sidelinkbold" target="mainFrame" onMouseOver=" window.status='Practical Test Booking'; return true" onMouseOut="window.status=' '; return true">Booking</a></td>
            -->
            <td class="sidetxtbold" width="100%"><a href="../s-bookTermMain.asp?fname=b%2D3c%2DSelectPracticalTestBooking%2Easp%3F%2B3" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Practical Test Booking'; return true" onmouseout="window.status=' '; return true">Booking</a></td>
        </tr>
        
        <tr valign="top">
            <td>&nbsp;</td>
            <td><img src="../image/site/icn-arrow-blue.gif">&nbsp;</td>
            <td width="100%"><a href="../b-3c-practicalTestCancel.asp?limit=pt" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Practical Test Cancel'; return true" onmouseout="window.status=' '; return true">Cancel</a></td>
        </tr>
        
        
        
        
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td class="sidetxtbold" colspan="2" onmouseover="window.status='Theory Test'" onmouseout="window.status=' '">Theory Test</td>
        </tr>
            
        <tr valign="top">
            <td>&nbsp;</td>
            <td><img src="../image/site/icn-arrow-blue.gif">&nbsp;</td>
            <!--
            <td width="100%"><a href="../b-selectTest.asp?action=book" class="sidelinkbold" target="mainFrame" onMouseOver=" window.status='Theory Test Booking'; return true" onMouseOut="window.status=' '; return true">Booking</a></td>
            -->
            <td width="100%"><a href="../s-bookTermMain.asp?fname=b%2DselectTest%2Easp%3Faction%3Dbook" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Theory Test Booking'; return true" onmouseout="window.status=' '; return true">Booking</a></td>
        </tr>
        
        <tr valign="top">
            <td>&nbsp;</td>
            <td><img src="../image/site/icn-arrow-blue.gif">&nbsp;</td>
            <td width="100%"><a href="../b-selectTest.asp?action=cancel" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Theory Test Cancel'; return true" onmouseout="window.status=' '; return true">Cancel</a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
      
        
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-trainSchedule&amp;His.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Training &amp; Test History'; return true" onmouseout="window.status=' '; return true">Training &amp; Test History</a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-bookTestStatement.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Booking Statement'; return true" onmouseout="window.status=' '; return true">Booking <br>Statement</a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-accountTransactions.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Account Transaction'; return true" onmouseout="window.status=' '; return true">Account <br>Transaction</a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        
        
        
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-membershipRenewal.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Membership Renewal'; return true" onmouseout="window.status=' '; return true">Membership Renewal</a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>       
        
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-transferFund.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Transfer Fund'; return true" onmouseout="window.status=' '; return true">Transfer Fund</a></td>
        </tr>       
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-changePassword.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Change Password'; return true" onmouseout="window.status=' '; return true">Change Password</a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
            <td colspan="2"><a href="../b-updateProfile.asp" class="sidelinkbold" target="mainFrame" onmouseover=" window.status='Update Profile'; return true" onmouseout="window.status=' '; return true">Update Profile</a></td>
        </tr>       
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>  
        
        
            
        
        <tr valign="top">
            <td><img src="../image/site/icn-4dot.gif">&nbsp;</td>
                <td colspan="2"><a href="#" onclick="logout('../b-logoutleonnew.asp');" class="sidelinkbold" onmouseover=" window.status='Logout'; return true" onmouseout="window.status=' '; return true">Logout</a></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
        </tr>
        </tbody></table>
    </td>
    </tr>
</tbody></table>
<!--<SCRIPT LANGUAGE=JAVASCRIPT SRC="../admin/inc-script/DisableRightMouseClick.js"></SCRIPT>-->

</body></html>

6
  • are you getting any error? Commented Jun 2, 2021 at 13:47
  • 1
    It would be much better if you share a link to that web page and mention what exactly element are you trying to click there Commented Jun 2, 2021 at 13:51
  • Show what is inside the last tr Commented Jun 2, 2021 at 14:00
  • What is exception stack trace ? Commented Jun 2, 2021 at 14:10
  • @itronic1990 I do have this error: [22760:17024:0603/231645.559:ERROR:device_event_log_impl.cc(214)] [23:16:45.559] USB: usb_device_handle_win.cc:1054 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) [22760:17024:0603/231645.563:ERROR:device_event_log_impl.cc(214)] [23:16:45.563] Bluetooth: bluetooth_adapter_winrt.cc:1072 Getting Default Adapter failed. Commented Jun 3, 2021 at 15:18

1 Answer 1

0

Try this:

element = WebDriverWait(driver, 30).until(

    EC.presence_of_element_located((By.XPATH, "//a[contains(text(),'Booking')]"))
)

element.click()
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the reply but it still doesn't seem to work. There are a few anchor tags with text 'Booking' but the one I am trying to access is the first of such element so I am unsure why it is unable to find it or any for that matter. I added the full page in the post.
You added a picture. Can you see elements properties there? I don't.
Updated: I added the code for the whole html element if it helps.
I see. What error are you getting there? Do you have to scroll to see that element or it is initially inside the page view?
No error. Nothing happens after the code. No need to scroll to see that element the whole page is visible when loaded.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.