Unable to locate the element - java

I am coding in Java using Selenium Webdriver. I am unable to find the LINK Text "License Manager" in the page. When I tried switching to frame called "text". Selenium was unable to locate the frame named "text" please help.
This is my code:
d.switchTo().frame("enterpriseStatus");
d.findElement(By.id("bannerSettingsButton")).click();//settings button
d.manage().timeouts().pageLoadTimeout(15000, TimeUnit.SECONDS);
d.switchTo().window("name=text");//This is where something goes wrong
d.findElement(By.linkText("License Manager")).click();
This is the frame source:
<body>
<div class="tablecontentarea-div" style="width: 90%;">
<table class="tabletitlebar">
<tr>
<td>
<span class="titlepage">Settings</span>
</td>
</tr>
</table>
<div class="tablecontentpanel" style="padding-top: 15px;">
<table style="width:100%" summary="">
<tr>
<td style="width:50%; padding-right:7px; vertical-align: top;">
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/servers_32x32.png"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Device Management</div>
<div>
Add, manage, configure and delete devices.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Getting Started</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">All Devices</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Manage Agent Assignments</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Policies</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Device Groups</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">NetApp Operations Manager</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Virtualization (Assign ESX Hosts)</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: Arrays</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: Databases</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/alerting_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Rules & Alerting</div>
<div>
Setup rules that can perform a variety of actions, including running scripts.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">All Rules</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Threshold Rules</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Windows Event Log Rules</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Asset Change Rules</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Scheduled Rules</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: Real Time</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Scripts</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/file_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Files</div>
<div>
Configure file analysis, file rules, assign shares to agents.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">File Analysis Rules</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Directory Analysis Rules</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">File Type Groups</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Assign Remote Shares</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Assign Local Shares</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: File Analysis</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">Discover VM Targets</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">File Repository</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/user_accounts_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Users</div>
<div>
Add, edit, and remove user accounts.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Manage Users</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: User Authentication</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td style="width:50%; padding-left:8px; vertical-align: top;">
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/server_profiler_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Storage Manager Server</div>
<div>
Configure and view information about your server.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: All</td>
</tr>
<tr>
<td valign="top">» </td>
<td valign="top">About</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: E-mail</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Data Retention</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/web_update_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">Updates & Upgrades</div>
<div>
Upload new modules and upgrade your agents and pollers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Upload Modules</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Upgrade Agents</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/reports_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">GUI & Reporter</div>
<div>
Configure GUI and Reporting behavior.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: Reporter</td>
</tr>
</table>
</td>
<td class="link-col-center">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Server Setup: GUI</td>
</tr>
</table>
</td>
<td class="link-col-right">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/license_36x36.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">License Summary</div>
<div>
View your license type and number of storage modifiers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">License Manager</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="setting-section">
<tr>
<td class="img-col">
<img src="/images/Icon.Thwack.gif"/>
</td>
<td class="desc-col">
<div class="titlesubwhitebg">thwack Community</div>
<div>
Import shared application templates posted on thwack, a community site for Solarwinds users. thwack features helpful devices, tips and downloads from over 20,000 network engineers.
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<table style="width:100%">
<tr>
<td class="link-col-left">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">» </td>
<td valign="top">Storage thwack Forum</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</body>

To switch to window you have to use WindowsHandle.
You may try using below function provided that you are handeling windows with different titles.
private String mainWindowsHandle; // Stores current window handle
public static boolean swithToWindow(WebDriver driver,String title){
mainWindowsHandle = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles(); // Gets all the available windows
for(String handle : handles)
{
driver.switchTo().window(handle); // switching back to each window in loop
if(driver.getTitle().equals(title)) // Compare title and if title matches stop loop and return true
return true; // We switched to window, so stop the loop and come out of funcation with positive response
}
driver.switchTo().window(mainWindowsHandle); // Switch back to original window handle
return false; // Return false as failed to find window with given title.
}

Related

Datatable - colspan dont showing correctly on Datatable

I have the next HTML Datatable
<div class="tabla-jquery">
<table id="comparativa-data-table" class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Titulo</th>
<th colspan="3">Fecha</th>
</tr>
</thead>
<tbody>
<tr>
<td>Prueba</td>
<td>Izda</td>
<td>Drha</td>
<td>Axial</td>
</tr>
</tbody>
</table>
</div>
And when I see the table, I get this error: Cannot read property 'fnSetData' of undefined
But when I change the HTML and put this:
<div class="tabla-jquery">
<table id="comparativa-data-table" class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Titulo</th>
<th>Fecha</th><th>Fecha</th><th>Fecha</th>
</tr>
</thead>
<tbody>
<tr>
<td>Prueba</td>
<td>Izda</td>
<td>Drha</td>
<td>Axial</td>
</tr>
</tbody>
</table>
</div>
It works "fine"(I only want a Fecha header instead of 3):
Anyone knows why occur this?
Thanks for your time!
Try like this :
<div class="tabla-jquery">
<table id="comparativa-data-table" class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Titulo</th>
<th colspan="3">Fecha</th>
<th style="display:none;">Fecha</th>
<th style="display:none;">Fecha</th>
</tr>
</thead>
<tbody>
<tr>
<td>Prueba</td>
<td>Izda</td>
<td>Drha</td>
<td>Axial</td>
</tr>
</tbody>
</table>

How to generate a PDF report from JSP page

I need to Generate PDF report in Java. Earlier when i use Cold Fusion it was easier to export html to PDF, is there any way to convert the html to pdf in JAVA.
I tried JSPDF javascript method to convert this page but that doesn't works.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>View JTC</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="assets/css/style.css" rel="stylesheet" type="text/css" />
<%
if (session.getAttribute("empid") == null) {
response.sendRedirect("index.jsp?message=Session Expired!!");
}
session.setAttribute("cpage", "production");
%>
<jsp:include page="navigationMenu.jsp" />
</head>
<body>
<section class="container-fluid">
<table class="table table-bordered">
<tr>
<th style="width:30%;vertical-align:middle;text-align:center;">logo</th>
<th colspan="2" style="text-align:center;width:70%">Denholm Yam Contracting Comapany L.L.C</th>
</tr>
<tr>
<th rowspan="2" style="text-align:center;vertical-align:middle;">Job Travel Card</th>
<th style="width:10%;">JTC No:</th>
<th></th>
</tr>
<tr>
<th>Date</th>
<th></th>
</tr>
</table>
<table class="table table-bordered">
<tr >
<td style="width:10%;text-align:left;">Project Number</td>
<td style="width:15%;text-align:left;" colspan="2"></td>
<td style="width:10%;text-align:left;">Unit No. / Tag No.</td>
<td style="width:15%;text-align:left;" colspan="4"></td>
</tr>
<tr>
<td>Area Number</td>
<td colspan="2"></td>
<td>Material Class</td>
<td colspan="4"></td>
</tr>
<tr>
<td style="width:15%;text-align:left;">Drawing No: / ISO Number</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:15%;text-align:left;">JC No:</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:10%;text-align:left;">Sheet No</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:10%;text-align:left;">Rev. No.</td>
<td style="width:15%;text-align:left;"></td>
</tr>
<tr>
<td style="width:15%;text-align:left;">Item Description</td>
<td style="width:15%;text-align:left;" colspan="2"></td>
<td style="width:15%;text-align:left;">ITP Stage Nos.</td>
<td style="width:15%;text-align:left;" colspan="4"></td>
</tr>
</table>
<!-- Fitup data -->
<table class="table table-bordered">
<tr>
<th rowspan="12" style="text-align:center;vertical-align:middle;">
<span class="verticaltext">
Fabrication Assembly Fit-Up
</span>
</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Weld/joint No</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Item/Position No.</th>
<th colspan="2">Material Spec Grade</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Size</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Thickness</th>
<th colspan="2">Heat/Plate/TestNo</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Welder No. for tracking</th>
<th colspan="2">Fitup Result</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Date</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2" >Sign</th>
</tr>
<tr>
<th>Material 1</th>
<th>Material 2</th>
<th>Material 1</th>
<th>Material 2</th>
<th>Accept</th>
<th>Reject</th>
</tr>
<c:forEach begin="1" var="xx" end="10">
<tr>
<c:if test="${xx==1}">
</c:if>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</c:forEach>
<tr>
<td colspan="4">Name & Signature of fabrication foreman</td>
<td colspan="3">Released to</td>
<td colspan="2">
<input type="checkbox">
QC/NDE/DIM.
</td>
<td colspan="1">
<input type="checkbox">
Welding
</td>
<td colspan="4">
<input type="checkbox">
Fabrication/Assembly
</td>
</tr>
<tr>
<td colspan="7">Date</td>
<td colspan="7">Date</td>
</tr>
</table>
<!-- welding data -->
<table class="table table-bordered">
<tr>
<th rowspan="13" style="text-align:center;vertical-align:middle;">
<span class="verticaltext">
Welding Details
</span>
</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">Joint No</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">WPS No.</th>
<th colspan="3" class="text-center">Welding Process</th>
<th colspan="3" class="text-center">Welder/Operation No.</th>
<th colspan="2" rowspan="2" class="text-center" >Visual Inspection</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">Date</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3" >Sign</th>
</tr>
<tr>
<th colspan="3" class="text-center">Passes</th>
<th colspan="3" class="text-center">Passes</th>
</tr>
<tr>
<th class="text-center">Root/Hot</th>
<th class="text-center">Fill</th>
<th class="text-center">Cap</th>
<th class="text-center">Root/Hot</th>
<th class="text-center">Fill</th>
<th class="text-center">Cap</th>
<th class="text-center">Accept</th>
<th class="text-center">Reject</th>
</tr>
<c:forEach begin="1" var="xx" end="10">
<tr>
<c:if test="${xx==1}">
</c:if>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</c:forEach>
<tr>
<td colspan="4">Name & Signature of fabrication foreman</td>
<td colspan="3">Released to</td>
<td colspan="2">
<input type="checkbox">
QC/NDE/DIM.
</td>
<td colspan="1">
<input type="checkbox">
Welding
</td>
<td colspan="4">
<input type="checkbox">
Fabrication/Assembly
</td>
</tr>
<tr>
<td colspan="14">Name & Signature of QC Personel</td>
</tr>
<tr>
<td colspan="7">Date</td>
<td colspan="7">Date</td>
</tr>
</table>
</section>
</div>
<script src="assets/jquery/customjs.js" type="text/javascript"></script>
<script src="assets/jquery/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="assets/jquery/popper.min.js" type="text/javascript"></script>
<script src="assets/jquery/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>
I need to export this page in landscape and all this content scaled into one page. Is there any way? Thank you in advance.
You can use Flyingsaucer.
Flying Saucer is a pure-Java library for rendering arbitrary
well-formed XML (or XHTML) using CSS 2.1 for layout and formatting,
output to Swing panels, PDF, and images.

Loop through a table using selenium webdriver

I have a table which can be found here: Ontario Gov Employee Directory and I'm trying to loop through the table to pull out the data, but struggling to find the xpath to be able to do so.
The table doesn't have an id, when I inspect the element I see:
<table title="results_list" border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="content" valign="top" align="right" width="50">1. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("32528")'>Aagaard, Lindsay</a>] [ Senior Policy Advisor ] [TREASURY BOARD SECRETARIAT]
<br>[DEPUTY PREMIER AND PRESIDENT OF THE TREASURY BOARD, Toronto]
<!-- [416-327-0948] -->
[416-327-0948] [
<a href="mailto:lindsay.aagaard#ontario.ca">
lindsay.aagaard#ontario.ca</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">2. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("34417")'>Aalto, Margaret</a>] [ Probation Officer ] [CHILDREN AND YOUTH SERVICES]
<br>[THUNDER BAY, Thunder Bay]
<!-- [807-475-1310] -->
[807-475-1310] [
<a href="mailto:margaret.aalto#ontario.ca">
margaret.aalto#ontario.ca</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">3. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("9187")'>Aarlaht, Andrew</a>] [ Business Analyst ] [COMMUNITY AND SOCIAL SERVICES]
<br>[HAMILTON, BUSINESS SERVICES UNIT, Hamilton]
<!-- [905-521-7335] -->
[905-521-7335] [
<a href="mailto:andrew.aarlaht#ontario.ca">
andrew.aarlaht#ontario.ca</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">4. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("9187")'>Aarlaht, Andrew</a>] [ Business Analyst ] [CHILDREN AND YOUTH SERVICES]
<br>[HAMILTON, BUSINESS SERVICES UNIT, Hamilton]
<!-- [905-521-7335] -->
[905-521-7335] [
<a href="mailto:andrew.aarlaht#ontario.ca">
andrew.aarlaht#ontario.ca</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">5. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("19146")'>Aarons, Drew</a>] [ Messenger ] [LEGISLATIVE OFFICES]
<br>[PARLIAMENTARY PROTOCOL, Toronto]
<!-- [416-325-7455] -->
[416-325-7455] [
<a href="mailto:daarons#ola.org">
daarons#ola.org</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">6. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("113729")'>Aaswaakshin, Neegann</a>] [ Articling Student ] [ABORIGINAL AFFAIRS]
<br>[LEGAL SERVICES, Toronto]
<!-- [416-212-2271] -->
[416-212-2271] [
<a href="mailto:Neegann.Aaswaakshin#ontario.ca">
Neegann.Aaswaakshin#ontario.ca</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">7. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("32196")'>Abad, Lilian</a>] [ Executive Assistant ] [TRANSPORTATION]
<br>[GO TRANSIT, Toronto]
<!-- [416-202-5506] -->
[416-202-5506] [
<a href="mailto:lilian.abad#gotransit.com">
lilian.abad#gotransit.com</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">8. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("114240")'>Abadesso, Jennifer</a>] [ Employment Program Consultant (Acting) ] [TRAINING, COLLEGES AND UNIVERSITIES]
<br>[FOUNDATION SKILLS, Toronto]
<!-- [416-327-2065] -->
[416-327-2065] [
<a href="mailto:jennifer.abadesso#ontario.ca">
jennifer.abadesso#ontario.ca</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">9. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("104293")'>Abakunzi, Louis</a>] [ Customer Service Representative (Bilingual) ] [GOVERNMENT AND CONSUMER SERVICES]
<br>[SERVICEONTARIO CONTACT CENTRE - NORTH YORK, Toronto]
<!-- [416-235-2999] -->
[416-235-2999] [
<a href="mailto:Louis.K.Abakunzi#ontario.ca">
Louis.K.Abakunzi#ontario.ca</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="content" valign="top" align="right" width="50">10. </td>
<td class="content">[<a class="results" href='javascript:showEmployeeDetail("19309")'>Aban, Edencio</a>] [ Audit Supervisor ] [ATTORNEY GENERAL]
<br>[AUDIT AND COMPLIANCE, Toronto]
<!-- [416-326-6295] -->
[416-326-6295] [
<a href="mailto:edencio.aban#agco.ca">
edencio.aban#agco.ca</a>]
</td>
</tr>
<tr>
<td> </td>
</tr>
</tbody>
</table>
How can I loop through the data in these rows?
It's a table within a table and then has some pretty standard formatting. What challenge are you having?
The table doesn't have an id, when I inspect the element I see:
It has other attributes you can use, like the title. Use the xpath //table[#title="results_list"]/tbody/tr/td to find each data element from the innermost table. Or remove the last /td from the xpath to get each row. After that, find each td element under it and use its text.
Note: The innermost table has 1st column with serial number and 2nd column with the actual data. I recommend getting each td and then using the 'innerHTML' attribute or elem.text. After that, use a regular exppresion to extract the different parts.
>>> all_tdata = driver.find_elements_by_xpath('//table[#title="results_list"]/tbody/tr/td')
>>> for td in all_tdata:
... print td.get_attribute('innerHTML') # save this in var and regex it
... # or
... data = td.text

Clicking element in table based on condition on another element in the same row

I have the following example structure for a table I'm looking at:
<tbody>
<tr class="OddRow">
<td class="TimeField">
7:20 AM
</td>
<td class="TextField"></td>
<td id="Price_2_1" class="MoneyField"></td>
<td class="LinkField">
<a id="basketControl_2_1" class="sr_AddToBasket">
Add to Basket
</a>
</td>
</tr>
<tr class="EvenRow">
<td class="TimeField"></td>
<td class="TextField"></td>
<td id="Price_2_2" class="MoneyField"></td>
<td class="LinkField"></td>
</tr>
...OddRow
...EvenRow
</tbody>
What I would like to be able to do is click (using selenium) on the element with class "sr_AddToBasket" when the value in class "TimeField" is something I specify. Only one row of the table can ever have the specified time in a particular instance.
I'm really stuck as to how to go about this so any help will be greatly appreciated! If it helps I'm currently attempting this in python, but have some knowledge of java.
Suppose your structure looks like below after you add two more rows:
<table>
<tbody>
<tr class="OddRow">
<td class="TimeField">
7:20 AM
</td>
<td class="TextField"></td>
<td id="Price_2_1" class="MoneyField"></td>
<td class="LinkField">
<a id="basketControl_2_1" class="sr_AddToBasket">
Add to Basket
</a>
</td>
</tr>
<tr class="EvenRow">
<td class="TimeField"></td>
<td class="TextField"></td>
<td id="Price_2_2" class="MoneyField"></td>
<td class="LinkField"></td>
</tr>
<tr class="OddRow">
<td class="TimeField"></td>
<td class="TextField"></td>
<td id="Price_2_1" class="MoneyField"></td>
<td class="LinkField"></td>
</tr>
<tr class="EvenRow">
<td class="TimeField">
9:00 PM
</td>
<td class="TextField"></td>
<td id="Price_2_2" class="MoneyField"></td>
<td class="LinkField">
<a id="basketControl_2_1" class="sr_AddToBasket">
Add to Basket
</a>
</td>
</tr>
</tbody>
</table>
So, now say you want to click on the 2nd link, then please use the below Java code:
driver.findElement(By.xpath("//td[#class='TimeField' and contains(text(),'9:00 PM')]/following-sibling::td/a[#class='sr_AddToBasket']")).click();
You can replace the '9:00 PM' above with your value.
if driver.find_elements_by_css_xpath("//tr[#class='EvenRow']/td[#class='TimeField']").get_attribute("value")=="your value":
driver.find_element_by_xpath("//a[#class='sr_AddToBasket']").click()
this get_attribute should return you the value you set and simple if condition matches the criteria of execution. Then next you find the link you want and click. I used xpath since it's helps us to identify element in a table easily.
you can use the following:
This question were answered here http://patch-recepteur.blogspot.com/2017/04/forum-clicking-element-in-table-based.html
<table>
<tbody>
<tr class="OddRow">
<td class="TimeField">
7:20 AM
</td>
<td class="TextField"></td>
<td id="Price_2_1" class="MoneyField"></td>
<td class="LinkField">
<a id="basketControl_2_1" class="sr_AddToBasket">
Add to Basket
</a>
</td>
</tr>
<tr class="EvenRow">
<td class="TimeField"></td>
<td class="TextField"></td>
<td id="Price_2_2" class="MoneyField"></td>
<td class="LinkField"></td>
</tr>
<tr class="OddRow">
<td class="TimeField"></td>
<td class="TextField"></td>
<td id="Price_2_1" class="MoneyField"></td>
<td class="LinkField"></td>
</tr>
<tr class="EvenRow">
<td class="TimeField">
9:00 PM
</td>
<td class="TextField"></td>
<td id="Price_2_2" class="MoneyField"></td>
<td class="LinkField">
<a id="basketControl_2_1" class="sr_AddToBasket">
Add to Basket
</a>
</td>
</tr>
</tbody>
</table>

Java based selenium webdriver - click on element in dynamically changing table content by row text ( click input by text in same row )

Im stucked in java based selenium usage, i like to click on input box (within table )by another cell text value
Here is my HTML code:
<DIV class=>
<P class=></P>
<UL></UL>
<FORM id="" onsubmit="" method=post name="" action="">
<TABLE width="100%">
<TBODY>
<TR>
<TD class=></TD></TR></TBODY></TABLE>
<TABLE>
<TBODY>
<TR>
<TD class=></TD></TR>
<TR>
<TD>
<TABLE class="" width="70%">
<TBODY>
<TR class="">
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD></TR>
<TR class="">
<TD><INPUT class="" onclick="" CHECKED type=checkbox><INPUT id= value=true type=hidden name=""> </TD>
<TD></TD>
<TD></TD>
<TD></TD></TR></TBODY></TABLE></TD>
<TR>
<TD><INPUT id="" class= onclick='' value="" type=button name=></TD></TR></TR></TBODY></TABLE>
<TABLE width="100%">
<TBODY>
<TR>
<TD class=""></TD></TR>
<TR>
<TD>
<TABLE class=foo width="100%">
<TBODY>
<TR class=foo-header>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD></TR>
<TR class="foo-odd">
<TD><INPUT onclick="" value="0" type="radio" name=""> </TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD></TR>
<TR class="foo-even">
<TD rowSpan="3"><INPUT onclick="" value="1" CHECKED type="radio" name=""> </TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD rowSpan="3"></TD>
<TD></TD>
<TD rowSpan="3"><INPUT id="" class="" value="" type="" name=""></TD></TR>
<TR class="foo-even">
<TD></TD></TR>
<TR class="foo">
<TD>CCC</TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><INPUT class="" onclick="" type=checkbox><INPUT id="" value="false" type="hidden" name=""> </TD></TR></TBODY></TABLE>
<TABLE width="100%">
<TBODY>
<TR>
<TD class=""></TD></TR>
<TR>
<TD>
<TABLE class="foo" width="100%">
<TBODY>
<TR class="foo-header">
<TD></TD>
<TD><BR><INPUT id="" class="" onclick="" value="" type="button" name=""></TD>
<TD colSpan="3"></TD>
<TD></TD></TR>
<TR class="foo-odd">
<TD><INPUT value="0" type="radio" name=""> </TD>
<TD></TD>
<TD></TD>
<TD colSpan="2"></TD>
<TD><SELECT class="" name=""> <OPTION value="0"></OPTION> <OPTION selected value="1"></OPTION></SELECT> </TD></TR>
<TR class="foo-even">
<TD rowSpan="2"><INPUT value="1" type="radio" name=""> </TD>
<TD rowSpan="2"></TD>
<TD rowSpan="2"></TD>
<TD></TD>
<TD></TD>
<TD rowSpan="2"><SELECT class="" name=""> <OPTION value="0"></OPTION> <OPTION selected value="1"></OPTION></SELECT> </TD></TR>
<TR class="foo">
<TD>CCC</TD>
<TD></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE width="100%">
<TBODY></TBODY></TABLE>
<TABLE width="100%">
<TBODY>
</DIV>
I like to click on the second CCC text row related input,(not by only clicking name or xpath) im tried with followings:
driver.findElement(By.xpath(".//td[contains(text(),'CCC')]/preceding-sibling::td")).click();
Code above working in a *very similar html only contains CCC one time (tested with another HTML code )
WebElement services = driver.findElement(By.xpath(".//*[#id='installationAddressForm']/table[4]/tbody/tr[2]/td/table/tbody/tr[4]/td[1][contains(text(),'CCC')]"));
String contents = services.getText();
System.out.println(contents);
Code above able to find text but when combined with the top code(/preceding-sibling::td) it cannot find the input
Please help.Thanks in advance
The expression td[1][contains(text(),'CCC')] selects the first td and tests whether its text contains CCC.
Replace it with td[contains(text(),'CCC')][1].

Categories