I am automating steps in a browser using Selenium/Python; however, I am stuck with trying to understand how to get Selenium to recognize a text value in a table and click on the URL in the corresponding row. The scenario we're trying to duplicate is a user logs into the website and searches for a login by username, and at that point the results will return in the UI. The results will be in a table like this, and we need to be able to find the Username and click on the User_ID which is clickable link to the user admin page.
User_ID Username Company_Name Name User_Status
Here is the HTML:
<tr onclick="window.location='?viewUsers=1&loginId=99999&customerId=1&token=9999999999999999999999'" onmouseover="onRowOver(this);" onmouseout="onRowOut(this);" style="cursor: pointer;">
<td class="bg8 resultTableRowBorderBottom">
<div class="font1 trNumbersAndDates">
<!---->
<a href="?viewUsers=1&loginId=99999&customerId=1&token=9999999999999999999999">
99999
</a>
<!---->
</div>
</td>
<!-- -->
<td class="bg8 resultTableRowBorderLeft resultTableRowBorderBottom">
<div class="font1 trStrings"> username@mail.com
</div>
</td>
<!-- -->
<td class="bg8 resultTableRowBorderLeft resultTableRowBorderBottom">
<div class="font1 trStrings"> Company Name
</div>
</td>
<!-- -->
<td class="bg8 resultTableRowBorderLeft resultTableRowBorderBottom">
<div class="font1 trStrings"> First Name
</div>
</td>
<!-- -->
<td class="bg8 resultTableRowBorderLeft resultTableRowBorderBottom">
<div class="font1 trStrings"> Status
</div>
</td>
<!-- -->
</tr>
Here is the code that I have so far for this piece... this is the line that I'm struggling with
click_user = driver.find_element_by_xpath("//tr[text() = '" + user_login.email + "']//a")
The user_login.email variable represents the username@mail.com in the html that is being passed in when the script kicks off.
click_user = driver.find_element_by_xpath("//tr[text() = '" + user_login.email + "']//a")
click_user.click()
timeout = 5
try:
element_present_3 = ec.presence_of_element_located((By.NAME, 'finish'))
WebDriverWait(driver, timeout).until(element_present_3)
except TimeoutException:
print("Timed out waiting for element to load")