all,
I am looking to use selenium chrome web driver to click a link in a table that is several layers deep in the page. but, essentially, there is a single page, with a nav menu for applications on the left and a main section in the centre of the page, which lists folders in a table with table links for software and documentation downloads. (They are just folders, and the files don't appear until the category is clicked) So, you click on the table link and the centre portion reloads with a full file list. However, when I try to select the software category, nothing happens... :(
Here is the inspect info
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
►<head> </head>
▼ <body id="treeMainBody" class="mainbody" onload="load(); registerServiceWorker(); checkSystemCapabilities (false); sho wHomePage(uuid, hasDefaultCommunity);">
<div id="backgroundFilter"></div>
►<div
id="topUploadWarningSection"></div>
►<nav class="core-navbar navbar navbar-expand flex-column flex-md-row bd-navbar"></nav> flex ▼<div class="main-container"> (flex
►<div id="tree-pane" class="panel-left ui-resizable">@</div>
▼ <div id="details" class="panel-right" style="min-height: 1069.36px;">
►<div id="dropFileHere" style="display:none" class="drop-file-here-container"></div>
<div class="main-detail" id="mainDetailDiv">
<form name="TreeClickForm" id="TreeClickForm" onsubmit="return false" method="post" style="margin-top:0px; ">
►<div class="col-12 right-section-boot"></div>
►<div class="col-12 top-button">
</div>
<!-- Upload section that appear/disappear when we click the upload button -->
►<div id="actionSection">@</div>
▼<div class="col-12 list-overflow">
▼<table id="inbox" class="table table-sm">
▼<thead class="inbox-header">
►<tr id="headerRow"></tr>
</thead>
<tbody class="inbox-row">
▼<tr class="inbox-row-single
►<td></td>
►<td width="1%" tabindex="0" onkeypress="if(isEnterKey(event)) { showFileList('42', 'Dat e', '1', 'True', 'True');}" onclick="showFileList('42', 'Date', '1', 'True', 'True');"></td> <td class="inbox-row">
▼**<a href="#" onkeypress="if(isEnterKey(event)){ showFileList('42', 'Date', '1', 'True', 'True') ;}" onclick="showFileList('42', 'Date', '1', 'True', 'True');"> == $0
" Software
</a>** </td>
<td class="inbox-row"> </td>
►<td align="right" class="inbox-row-selected">@</td>
<td align="right" class="inbox-row"> </td>
►<td align="right" class="inbox-row-actions inbox-row"></td>
</tr>
▼<tr class="inbox-row-single ">
▼ <td>
<input type="hidden" id="row0k_1" value="true">
<input type="hidden" id="rowClick_1" value="showFileList('7', 'Date', '1', 'True', 'True');"> <input type="hidden" id="nodeId_1" value="31387">
<input type="checkbox" name="checkbox_1" id="checkbox_1" title>
</td>
►<td width="1%" tabindex="0" onkeypress="if(isEnterKey(event)) { showFileList('7', 'Date', '1', 'Tru e', 'True');}" onclick="showFileList('7', 'Date', '1', 'True', 'True');"></td>
<td class="inbox-row"></td>
<td class="inbox-row"> </td>
►<td align="right" class="inbox-row-selected">@</td>
<td align="right" class="inbox-row"> </td>
►<td align="right" class="inbox-row-actions inbox-row"> </td>
</tr>
►<tr class="inbox-row-single "></tr>
</tbody>
Is there a way to get the element by wildcarding the xpath value?
I tried to do it this way, but it is not really working that well. I am trying to target this href...
▼**<a href="#" onkeypress="if(isEnterKey(event)){ showFileList('42', 'Date', '1', 'True', 'True') ;}" onclick="showFileList('42', 'Date', '1', 'True', 'True');"> == $0
" Software
</a>** </td>
with this code
try:
softwareMenuItem = WebDriverWait(browser, search_timeout).until(EC.presence_of_element_located((By.XPATH, "//*/*[contains(text(), 'Software')]")))
except Exception:
print("Searching for Software menu item was not found.")
softwareMenuItem.click()
Do I need to have ten levels of "/*" to target the right level or is there a better way to target the link I want with only a tiny bit of info in the href link.
ta,
x
Try with below lines once.
a
and its text. Also check if the Xpath is able to highlight the element in the DOM as 1/1 match.
And since you are trying to click on that element, wait till its clickable.softwareMenuItem = WebDriverWait(browser, search_timeout).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(),'Software')]")))
a
tag.softwareMenuItem = WebDriverWait(browser, search_timeout).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, 'Software')))