all I have a company webpage I’m trying to use selenium with and I have it navigating through the login page and process. But I need selenium to click a button inside a nav bar. But for some reason I’ve tried numerous ways of clicking it and it’s just not finding it in selenium. Here is my current code snippet for clicking the nav button that doesn’t work. Unfortunately, I can’t give the access to the page for help as its company page. But I’ve tried to copy the Html of the button I’m looking to click for possible help?
def click_document_button(self):
try:
# Wait for the sidebar to be present
WebDriverWait(self.driver, 30).until(
EC.presence_of_element_located((By.ID, "mysidebar"))
)
# Scroll to the sidebar to ensure the "Documents" button is visible
sidebar = self.driver.find_element(By.ID, "mysidebar")
self.driver.execute_script("arguments[0].scrollIntoView();", sidebar)
# Wait for the "Documents" link to be clickable and click it
documents_link = WebDriverWait(self.driver, 30).until(
EC.element_to_be_clickable((By.XPATH, "//a[@href='#Documents']"))
)
documents_link.click()
except Exception as e:
print(f"Error clicking the Documents button: {e}")
Here is the html code that I’m trying to click. Its a nav bar inside of a couple div classes it doesnt move but only is there with proper login credentials to view. (I have the login access to view it).
<a href="#Documents">Documents</a>
<div class="sidebar affix" style="top: auto;">
<p>
</p><div class="tyler-toggle-controller noprint row">
<div class="col-md-12">
<button class="btn btn-default btn-block" type="button" onclick="toggleElementVisible('PrintMask'); toggleElementVisible('PrintNav');">
<span>
Print
</span>
</button>
</div>
</div>
<p></p>
<div id="PrintNav" class="tyler-hide row noprint">
<div class="col-md-12">
<div class="panel panel-default print-dialog">
<div class="panel-body">
<br>
<div id="PrintDiv" class="noprint print-sections">
<h4>Please select the sections that you would like to print</h4>
<div class="row">
<div class="col-md-12">
<div class="form-check-box pull-left">
<input id="SelectAllSectionsChkBx" type="checkbox" checked="checked" aria-label="Select All" wfd-id="id50">
<span class="ClickThroughIE"></span>
<label class="ClickThroughIE">
Select All
</label>
</div>
</div>
</div>
<div class="form-check-box col-md-12 container">
<input id="InformationDiv_Print" type="checkbox" checked="checked" aria-label="Select Information" wfd-id="id51">
<span class="ClickThroughIE"></span>
<label class="ClickThroughIE">Case Information</label>
</div>
<div class="form-check-box col-md-12 container">
<input id="PartiesPrintSection_Print" type="checkbox" checked="checked" aria-label="Select Party" wfd-id="id52">
<span class="ClickThroughIE"></span>
<label class="ClickThroughIE">Party</label>
</div>
<div class="form-check-box col-md-12 container">
<input id="EventsPrintSection_Print" type="checkbox" checked="checked" aria-label="Select Events" wfd-id="id53">
<span class="ClickThroughIE"></span>
<label class="ClickThroughIE">Disposition Events</label>
</div>
<div class="form-check-box col-md-12 container">
<input id="OtherEventsPrintSection_Print" type="checkbox" checked="checked" aria-label="Select Other Events" wfd-id="id54">
<span class="ClickThroughIE"></span>
<label class="ClickThroughIE">Events and Hearings</label>
</div>
<div class="form-check-box col-md-12 container">
<input id="FinancialInfoPrintSection_Print" type="checkbox" checked="checked" aria-label="Select Financial" wfd-id="id55">
<span class="ClickThroughIE"></span>
<label class="ClickThroughIE">Financial</label>
</div>
<div class="form-check-box col-md-12 container">
<input id="DocumentsPrintSection_Print" type="checkbox" checked="checked" aria-label="Select Documents" wfd-id="id56">
<span class="ClickThroughIE"></span>
<label class="ClickThroughIE">Documents</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a href="#" id="SectionPrintButton" class="row-buff btn btn-primary pull-right" role="button" style="color:white;">Print</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="PrintMask">
<p>
</p><div class="row">
<div class="col-md-12">
<div class="portlet-summary-actions">
</div>
</div>
</div>
<p></p>
<div class="row">
<div class="col-md-12">
<nav id="mysidebar" class="bs-docs-sidebar hidden-print hidden-xs hidden-sm">
<div>
<ul class="nav bs-docs-sidenav">
<li class=""><a href="#Information">Information</a></li>
<li class="active"><a href="#PartyInformation">Party</a></li>
<li class=""><a href="#Events">Events</a></li>
<li class=""><a href="#OtherEvents">Other Events</a></li>
<li class=""><a href="#FinancialInfo">Financial</a></li>
<li class=""><a href="#Documents">Documents</a></li>
</ul>
<a id="BackToTop" class="back-to-top" href="#top">Back to top</a>
</div>
</nav>
</div>
</div>
</div>
</div>
Any help would be appreciated.