I am unable to locate the date, month and year in bootstrap date picker. While I am trying to inspect the element in calendar, the calendar is getting closed and unable to locate the element.
It should not be a problem to open the page, click the control which is responsible for showing the calendar and invoke WebDriver.getPageSource() function.
Example code (it uses WebDriverWait to ensure that the calendar widget is there as it might be the case it's loaded after DOM is ready due to asynchronous nature of AJAX calls) :
driver.get("https://eonasdan.github.io/bootstrap-datetimepicker/");
new WebDriverWait(driver, 10)
.until(ExpectedConditions
.elementToBeClickable(By
.xpath("//span[contains(#class,'calendar')]")))
.click();
Files.write(Paths.get("response.html"), driver.getPageSource().getBytes(StandardCharsets.UTF_8));
Example output from the above page:
<div class="bootstrap-datetimepicker-widget dropdown-menu bottom"
style="display: block; top: 34px; bottom: auto; left: 0px; right: auto;">
<ul class="list-unstyled">
<li class="collapse in">
<div class="datepicker">
<div class="datepicker-days" style="display: block;">
<table class="table-condensed">
<thead>
<tr>
<th class="prev" data-action="previous"><span
class="glyphicon glyphicon-chevron-left"
title="Previous Month"></span></th>
<th class="picker-switch" data-action="pickerSwitch"
colspan="5" title="Select Month">July 2019
</th>
<th class="next" data-action="next"><span
class="glyphicon glyphicon-chevron-right"
title="Next Month"></span></th>
</tr>
<tr>
<th class="dow">Su</th>
<th class="dow">Mo</th>
<th class="dow">Tu</th>
<th class="dow">We</th>
<th class="dow">Th</th>
<th class="dow">Fr</th>
<th class="dow">Sa</th>
</tr>
</thead>
<tbody>
<tr>
<td data-action="selectDay" data-day="06/30/2019"
class="day old weekend">30
</td>
<td data-action="selectDay" data-day="07/01/2019"
class="day">1
</td>
<td data-action="selectDay" data-day="07/02/2019"
class="day">2
</td>
<td data-action="selectDay" data-day="07/03/2019"
class="day">3
</td>
<td data-action="selectDay" data-day="07/04/2019"
class="day">4
</td>
<td data-action="selectDay" data-day="07/05/2019"
class="day">5
</td>
<td data-action="selectDay" data-day="07/06/2019"
class="day weekend">6
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="07/07/2019"
class="day weekend">7
</td>
<td data-action="selectDay" data-day="07/08/2019"
class="day">8
</td>
<td data-action="selectDay" data-day="07/09/2019"
class="day">9
</td>
<td data-action="selectDay" data-day="07/10/2019"
class="day">10
</td>
<td data-action="selectDay" data-day="07/11/2019"
class="day">11
</td>
<td data-action="selectDay" data-day="07/12/2019"
class="day">12
</td>
<td data-action="selectDay" data-day="07/13/2019"
class="day weekend">13
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="07/14/2019"
class="day weekend">14
</td>
<td data-action="selectDay" data-day="07/15/2019"
class="day">15
</td>
<td data-action="selectDay" data-day="07/16/2019"
class="day">16
</td>
<td data-action="selectDay" data-day="07/17/2019"
class="day">17
</td>
<td data-action="selectDay" data-day="07/18/2019"
class="day">18
</td>
<td data-action="selectDay" data-day="07/19/2019"
class="day">19
</td>
<td data-action="selectDay" data-day="07/20/2019"
class="day weekend">20
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="07/21/2019"
class="day weekend">21
</td>
<td data-action="selectDay" data-day="07/22/2019"
class="day active today">22
</td>
<td data-action="selectDay" data-day="07/23/2019"
class="day">23
</td>
<td data-action="selectDay" data-day="07/24/2019"
class="day">24
</td>
<td data-action="selectDay" data-day="07/25/2019"
class="day">25
</td>
<td data-action="selectDay" data-day="07/26/2019"
class="day">26
</td>
<td data-action="selectDay" data-day="07/27/2019"
class="day weekend">27
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="07/28/2019"
class="day weekend">28
</td>
<td data-action="selectDay" data-day="07/29/2019"
class="day">29
</td>
<td data-action="selectDay" data-day="07/30/2019"
class="day">30
</td>
<td data-action="selectDay" data-day="07/31/2019"
class="day">31
</td>
<td data-action="selectDay" data-day="08/01/2019"
class="day new">1
</td>
<td data-action="selectDay" data-day="08/02/2019"
class="day new">2
</td>
<td data-action="selectDay" data-day="08/03/2019"
class="day new weekend">3
</td>
</tr>
<tr>
<td data-action="selectDay" data-day="08/04/2019"
class="day new weekend">4
</td>
<td data-action="selectDay" data-day="08/05/2019"
class="day new">5
</td>
<td data-action="selectDay" data-day="08/06/2019"
class="day new">6
</td>
<td data-action="selectDay" data-day="08/07/2019"
class="day new">7
</td>
<td data-action="selectDay" data-day="08/08/2019"
class="day new">8
</td>
<td data-action="selectDay" data-day="08/09/2019"
class="day new">9
</td>
<td data-action="selectDay" data-day="08/10/2019"
class="day new weekend">10
</td>
</tr>
</tbody>
</table>
</div>
<div class="datepicker-months" style="display: none;">
<table class="table-condensed">
<thead>
<tr>
<th class="prev" data-action="previous"><span
class="glyphicon glyphicon-chevron-left"
title="Previous Year"></span></th>
<th class="picker-switch" data-action="pickerSwitch"
colspan="5" title="Select Year">2019
</th>
<th class="next" data-action="next"><span
class="glyphicon glyphicon-chevron-right"
title="Next Year"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7"><span data-action="selectMonth"
class="month">Jan</span><span
data-action="selectMonth"
class="month">Feb</span><span
data-action="selectMonth"
class="month">Mar</span><span
data-action="selectMonth"
class="month">Apr</span><span
data-action="selectMonth"
class="month">May</span><span
data-action="selectMonth"
class="month">Jun</span><span
data-action="selectMonth"
class="month active">Jul</span><span
data-action="selectMonth"
class="month">Aug</span><span
data-action="selectMonth"
class="month">Sep</span><span
data-action="selectMonth"
class="month">Oct</span><span
data-action="selectMonth"
class="month">Nov</span><span
data-action="selectMonth" class="month">Dec</span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="datepicker-years" style="display: none;">
<table class="table-condensed">
<thead>
<tr>
<th class="prev" data-action="previous"><span
class="glyphicon glyphicon-chevron-left"
title="Next Decade"></span></th>
<th class="picker-switch" data-action="pickerSwitch"
colspan="5" title="Select Decade">2014-2025
</th>
<th class="next" data-action="next"><span
class="glyphicon glyphicon-chevron-right"
title="Previous Decade"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7"><span data-action="selectYear" class="year">2014</span><span
data-action="selectYear"
class="year">2015</span><span
data-action="selectYear"
class="year">2016</span><span
data-action="selectYear"
class="year">2017</span><span
data-action="selectYear"
class="year">2018</span><span
data-action="selectYear"
class="year active">2019</span><span
data-action="selectYear"
class="year">2020</span><span
data-action="selectYear"
class="year">2021</span><span
data-action="selectYear"
class="year">2022</span><span
data-action="selectYear"
class="year">2023</span><span
data-action="selectYear"
class="year">2024</span><span
data-action="selectYear" class="year">2025</span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="datepicker-decades" style="display: none;">
<table class="table-condensed">
<thead>
<tr>
<th class="prev" data-action="previous"><span
class="glyphicon glyphicon-chevron-left"
title="Previous Century"></span></th>
<th class="picker-switch" data-action="pickerSwitch"
colspan="5">1999-2099
</th>
<th class="next" data-action="next"><span
class="glyphicon glyphicon-chevron-right"
title="Next Century"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7"><span data-action="selectDecade"
class="decade" data-selection="2005">2000 - 2011</span><span
data-action="selectDecade" class="decade"
data-selection="2017">2012 - 2023</span><span
data-action="selectDecade" class="decade"
data-selection="2029">2024 - 2035</span><span
data-action="selectDecade" class="decade"
data-selection="2041">2036 - 2047</span><span
data-action="selectDecade" class="decade"
data-selection="2053">2048 - 2059</span><span
data-action="selectDecade" class="decade"
data-selection="2065">2060 - 2071</span><span
data-action="selectDecade" class="decade"
data-selection="2077">2072 - 2083</span><span
data-action="selectDecade" class="decade"
data-selection="2089">2084 - 2095</span><span
data-action="selectDecade" class="decade"
data-selection="2101">2096 - 2107</span><span></span><span></span><span></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</li>
<li class="picker-switch accordion-toggle">
<table class="table-condensed">
<tbody>
<tr>
<td><a data-action="togglePicker" title="Select Time"><span
class="glyphicon glyphicon-time"></span></a></td>
</tr>
</tbody>
</table>
</li>
<li class="collapse">
<div class="timepicker">
<div class="timepicker-picker">
<table class="table-condensed">
<tbody>
<tr>
<td><a href="#" tabindex="-1" title="Increment Hour"
class="btn" data-action="incrementHours"><span
class="glyphicon glyphicon-chevron-up"></span></a>
</td>
<td class="separator"></td>
<td><a href="#" tabindex="-1" title="Increment Minute"
class="btn" data-action="incrementMinutes"><span
class="glyphicon glyphicon-chevron-up"></span></a>
</td>
<td class="separator"></td>
</tr>
<tr>
<td><span class="timepicker-hour"
data-time-component="hours" title="Pick Hour"
data-action="showHours">05</span></td>
<td class="separator">:</td>
<td><span class="timepicker-minute"
data-time-component="minutes" title="Pick Minute"
data-action="showMinutes">46</span></td>
<td>
<button class="btn btn-primary"
data-action="togglePeriod" tabindex="-1"
title="Toggle Period">PM
</button>
</td>
</tr>
<tr>
<td><a href="#" tabindex="-1" title="Decrement Hour"
class="btn" data-action="decrementHours"><span
class="glyphicon glyphicon-chevron-down"></span></a>
</td>
<td class="separator"></td>
<td><a href="#" tabindex="-1" title="Decrement Minute"
class="btn" data-action="decrementMinutes"><span
class="glyphicon glyphicon-chevron-down"></span></a>
</td>
<td class="separator"></td>
</tr>
</tbody>
</table>
</div>
<div class="timepicker-hours" style="display: none;">
<table class="table-condensed">
<tbody>
<tr>
<td data-action="selectHour" class="hour">12</td>
<td data-action="selectHour" class="hour">01</td>
<td data-action="selectHour" class="hour">02</td>
<td data-action="selectHour" class="hour">03</td>
</tr>
<tr>
<td data-action="selectHour" class="hour">04</td>
<td data-action="selectHour" class="hour">05</td>
<td data-action="selectHour" class="hour">06</td>
<td data-action="selectHour" class="hour">07</td>
</tr>
<tr>
<td data-action="selectHour" class="hour">08</td>
<td data-action="selectHour" class="hour">09</td>
<td data-action="selectHour" class="hour">10</td>
<td data-action="selectHour" class="hour">11</td>
</tr>
</tbody>
</table>
</div>
<div class="timepicker-minutes" style="display: none;">
<table class="table-condensed">
<tbody>
<tr>
<td data-action="selectMinute" class="minute">00</td>
<td data-action="selectMinute" class="minute">05</td>
<td data-action="selectMinute" class="minute">10</td>
<td data-action="selectMinute" class="minute">15</td>
</tr>
<tr>
<td data-action="selectMinute" class="minute">20</td>
<td data-action="selectMinute" class="minute">25</td>
<td data-action="selectMinute" class="minute">30</td>
<td data-action="selectMinute" class="minute">35</td>
</tr>
<tr>
<td data-action="selectMinute" class="minute">40</td>
<td data-action="selectMinute" class="minute">45</td>
<td data-action="selectMinute" class="minute">50</td>
<td data-action="selectMinute" class="minute">55</td>
</tr>
</tbody>
</table>
</div>
</div>
</li>
</ul>
</div>
Related
How we can get the Table(in a webpage) row using the value it contain.
Suppose a table of 3*3. In that cell(2,3) cell text is "Test". So how to find the row number = 2 using the the cell text "Test".
Selenium-2.53.1
Java-8
This is the xpath
//table[2]/tbody/tr/td[2]/table[2]/tbody/tr[7]/td/div[2]/table/tbody/tr[1]/td[1]/div/a/font
in which bolded tr (here tr[1]) is the row I want to change dynamically & the text is inside the bolded td (here td[1])
My html code is :
<html>
<head></head>
<body>
<form name="fm" method="post">
<table>
<!-- --Some data--- -->
</table>
<table width="100%" height="100%" border="0" >
<tr valign="top" >
<td width="200" height="100%" rowspan="3" align="center" >
<p></p>
<table width="89%" height="270" border="0">
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<!-- --Some data--- -->
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td><table width="100%" height="71" border="0" align="right">
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<!-- --Some data--- -->
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table>
<p></p>
</td>
<td width="622" height="30" colspan="3" align="left" valign="top">
<table width="100%" height="40" align="center">
<tr><!-- --Some data--- --></tr>
</table>
<table width="476" height="110" align="center">
<tr></tr>
<tr></tr>
<tr></tr>
<!-- --Some data--- -->
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td height="22" colspan="3">
<div align="left">
<table width="469" border="1">
<tr bgcolor="#006291">
<td width="81" bgcolor="#006291"><div align="center">SlNo.</div></td>
<td width="82" bgcolor="#006291"><div align="center">Code</div></td>
<td width="300" bgcolor="#006291"><div align="center">Name</div></td>
</tr>
</table>
</div>
<div align="left" style="width:465px;Height:150px;">
<table width="465" bgcolor="#FFFFFF" border="1">
<tr bordercolor="#006291" bgcolor='#FFEADF' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >1</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >01</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm1</font></div></td>
</tr>
<tr bordercolor="#006291" bgcolor='#F1F8FC' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >2</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >02</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm2</font></div></td>
</tr>
<tr bordercolor="#006291" bgcolor='#FFEADF' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >3</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >03</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm3</font></div></td>
</tr>
<tr bordercolor="#006291" bgcolor='#F1F8FC' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >4</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >04</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm4</font></div></td>
</tr>
<tr bordercolor="#006291" bgcolor='#FFEADF' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >5</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >10</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm5</font></div></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
"count(//table[#id='tableid']//td[.='Test']/parent::tr/preceding-sibling::tr) + 1"
put in your own table identifier... depends on it being a simple table without rowspans and colspans.
I tried capturing the column data of all rows into a List(observe the xpath of 'rowList' below, no number given for the final 'tr' which gets the column data for all rows), and using foreach got the index of the row which contains required text.
Will have to change the value in 'expRowValue' to have it worked with different data.
public class Table {
WebDriver driver;
By rowList = By.xpath("html/body/div[1]/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td[1]/table[1]/tbody/tr[3]/td/table/tbody/tr/td[2]");
#Test
public void f() {
String expRowValue="$513";
System.setProperty("webdriver.chrome.driver", "C:/Users/dell/Downloads/chromedriver/chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
driver.manage().window().maximize();
List<WebElement>rowsData = driver.findElements(rowList);
int k=1;
for (WebElement rowValue: rowsData) {
if (rowValue.getText().equals(expRowValue)){
System.out.println("ROw Index::" + k);
}
k++;
}
}
}
If you want to click on <td> on the basis of text try below xpath :-
.//td[child::a/font[text() = 'your text hare']]
Or if you to click on <a> inside <td> on the basis of text try below xpath :-
.//td/a[child::font[text() = 'your text hare']]
Or it you want to click on table cell using their row and column index follow this link
URL oracle = new URL("hurlAddress/dinfo.cgi");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
I get
<html>
<head>
<!-- RUI RC=100 -->
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Don't open this page!</title>
</head>
<body bgcolor="#C0C0C0">
<center>
<table border="0" cellpadding="0" cellspacing="4" width="400">
<tr><td align="center" valign="top" width="48">
<img src="en/media/ss_wrn.gif" border="0" width=32 height=32>
</td>
<td>
<font size="4" face="Helvetica,Arial">
<b>User information is disabled.</b><br>
This operation cannot be accepted. User certification is invalid or date expired.<br>
Update page.<br>
</font>
</td>
</tr>
<tr><td></td>
<td align="right">
<img src="en/media/b_ok.gif" border="0" alt="OK" title="OK">
</td>
</tr>
</table>
</center>
</body>
I was expecting
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Remote UI:Device Information</title>
</head>
<body bgcolor="white" link="blue" alink="red" vlink="blue">
<a name="page_top"></a>
<form>
<SCRIPT LANGUAGE="JavaScript">
var has_fax = false; // true or false
var Fax_Type = "0"; // 0(None),1(PSTN),2(PSTNx2),3(ISDN)
var has_send =true; // has send
var is_oem = false;
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
function reload_device(){
var cgi_str = "./dinfo.cgi?";
// for Expire Cache!!
var now_time = new Date();
cgi_str += "Dummy=" + now_time.getTime();
document.location.href = cgi_str;
}
</SCRIPT>
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td valign="middle"><font size="4" color="#000066"><b><table border="0" cellpadding="0" cellspacing="2">
<tr>
<td rowspan="2" nowrap><img src="en/media/imgs030.gif"></td>
<td nowrap><font face="Helvetica,Arial" size="4" color="#000066"><b>slq29986</b></font></td>
</tr>
<tr>
<td nowrap><font size="2">iR5570</font></td>
</tr>
</table></b></font></td>
<td valign="middle" width="70" align="right"><font size="4" color="black"><b><img src="en/media/bh_updt.gif" width="28" height="28" border="0" alt="Update" title="Update"></b></font></td>
</tr>
</table>
<hr noshade size="2">
<table border="0" cellpadding="0" cellspacing="4" width="100%">
<tr>
<td align="left"><font size="1"> Last Updated :05/26/2016 19:30:54</font></td>
</tr>
</table><table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr height="26">
<td bgcolor="#000066" height="26"><font color="white" face="Helvetica,Arial"><b> Device Information</b></font></td>
</tr>
</table><table border="0" cellspacing="2" cellpadding="2" width="100%">
<SCRIPT LANGUAGE="JavaScript">
if(is_oem == false)
{
document.write('<tr>');
document.write('<td width="3%"></td>');
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Manufacturer :</font></td>');
document.write('<td><font size="4">CANON INC</font></td>');
document.write('</tr>');
}
</SCRIPT>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Device Name :</font></td>
<td><font size="4">slq29986</font></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Location :</font></td>
<td><font size="4">MESAAS</font></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Product Name : </font></td>
<td>iR5570</td>
</tr>
<tr>
<td colspan="3"><hr size="1"></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Serial Number :</font></td>
<td>SLQ29986</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Main Board Version :</font></td>
<td>1</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Controller Version :</font></td>
<td>3604.838.3201</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Scanner Version :</font></td>
<td>401.100</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Finisher Version :</font></td>
<td>801</td>
</tr>
<SCRIPT LANGUAGE="JavaScript">
if(has_send == true)
{
document.write('<tr>');
document.write('<td colspan="3">');
document.write('<hr size="1">');
document.write('</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width="3%"></td>');
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Receive E-mail Address :</font></td>');
document.write('<td>aaa#aaa.edu</td>');
document.write('</tr>');
}
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
if( has_fax == true )
{
document.write('<tr>');
document.write('<td colspan="3">');
document.write('<hr size="1">');
document.write('</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width="3%"></td>');
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Telephone Number :</font></td>');
document.write('<td></td>');
document.write('</tr>');
if( Fax_Type == "3" )
{
document.write('<tr>');
document.write('<td width="3%"></td>');
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Subaddress :</font></td>');
document.write('<td></td>');
document.write('</tr>');
}
}
</SCRIPT>
<tr>
<td colspan="3">
<hr size="1">
</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">System Manager :</font></td>
<td>MESAAS</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Contact Information :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">E-mail Address :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Support :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Administrator Comment (E-mail) :</font></td>
<td></td>
</tr>
<tr>
<td colspan="3">
<hr size="1">
</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Contact Person :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Phone :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Comment (E-mail) :</font></td>
<td></td>
</tr>
</table>
<p>
<hr size="2">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td valign="bottom"><img src="en/media/ba_ptp.gif" border="0" hspace="2" vspace="2" alt="Back to the Top on This Page" title="Back to the Top on This Page"></td>
</tr>
</table>
</form>
</body>
</html>
Thanks to amitmah and Gilbert Le Blanc I installed
httpfox addon on firefox and I noticed that I need to set a cookie
URL url = new URL("urlAddress/dinfo.cgi");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Cookie", "iR=7472571");
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))){
StringBuilder builder = new StringBuilder();
int cp;
while ((cp = in.read()) != -1) {
builder.append((char) cp);
}
return builder.toString();
}
In browser this cookie is set if I access first urlAddress. If I tried to access directly urlAddress/dinfo.cgi I get the same "User information is disabled..." response.
I try to execute this code it will show the following error:
java.sql.SQLException.Operation not allowed after ResultSet closed
This is my code.in this code itself shows the above error..
<table cellspacing="0">
<%
try{
ResultSet rs1=st.executeQuery("select u.post_id,u.userid,u.post_txt from requestdetails as r inner join user_post as u on r.frdname=u.userid where r.userid='"+id+"'");
while(rs1.next()){
int post_id=rs1.getInt(1);
int fid=rs1.getInt(2);
System.out.println("iiii "+fid);
String text=rs1.getString(3);
System.out.println("txttt "+text);
ResultSet rs3=stat.executeQuery("select * from userdetails where userid='"+fid+"'");
if(rs3.next()){
String na=rs3.getString("username");
System.out.println("username "+na);
String img=rs3.getString("profilepic");
System.out.println("imgee "+img);
%>
<tr>
<td width="5%" style="padding-left:25;" rowspan="2"> <img src="images/<%=img%>" height="60" width="55"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3" style="padding:7;"><%=rs3.getString("username") %> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td colspan="3" style="padding-left:7;"><%=text %></td>
</tr>
<%
ResultSet rr=st.executeQuery("select * from comment_status where post_id='"+post_id+"'");
while(rr.next()){
int uid=rr.getInt("userid");
String cmt=rr.getString("comment");
ResultSet rrr=stat.executeQuery("select * from userdetails where userid='"+uid+"'");
if(rrr.next()){
%>
<tr>
<td> </td>
<td width="4%" bgcolor="#EDEFF4" style="padding-left:12;" rowspan="2"> <img src="" height="40" width="47"> </td>
<td bgcolor="#EDEFF4" style="padding-left:7;" > <%=rrr.getString("username") %> </td>
<td align="right" rowspan="2" bgcolor="#EDEFF4">
</tr>
<tr>
<td> </td>
<td bgcolor="#EDEFF4" style="padding-left:7;" colspan="2"><%=cmt %></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<%
}
}
%>
<tr>
<td> </td>
<td width="4%" style="padding-left:17;" bgcolor="#EDEFF4" rowspan="2"> <img src="images/" height="33" width="33"> </td>
<td bgcolor="#EDEFF4" colspan="2" style="padding-top:15;">
<form method="post" name="commenting" onSubmit="return blank_comment_check()" action="commentstatus.jsp">
<input type="text" name="comment_txt" placeholder="Write a comment..." maxlength="420" style="width:100px;" id="">
<input type="hidden" name="postid" value="<%=post_id%>">
<input type="hidden" name="userid" value="">
<input type="submit" name="comment" style="display:none;">
</form>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4"align="right" style="border-top:outset; border-top-width:thin;"> </td>
</tr>
<%
}
}
}catch(Exception e){
e.printStackTrace();
}
%>
</table>
</div>
I don't know what mistake I've done in above code.
After I change the code like this, it's working fine...
Statement stt=con.createStatement();
ResultSet rs1=stt.executeQuery("select u.post_id,u.userid,u.post_txt from requestdetails as r inner join user_post as u on r.frdname=u.userid where r.userid='"+id+"'");
while(rs1.next()){
int post_id=rs1.getInt(1);
int fid=rs1.getInt(2);
System.out.println("iiii "+fid);
String text=rs1.getString(3);
System.out.println("txttt "+text);
Statement st1=con.createStatement();
ResultSet rs3=st1.executeQuery("select * from userdetails where userid='"+fid+"'");
if(rs3.next()){
String na=rs3.getString("username");
System.out.println("username "+na);
String img=rs3.getString("profilepic");
System.out.println("imgee "+img);
I made the mistake of using the same statement for all queries.
When I created different statements object for the solution it works fine.
I'm trying to link a product from the category.jsp page to its own product.jsp page. When I click on a given product on the category page, the link in the browser displays perfectly as supposed to: http://localhost:8080/ecommerce/product?389 but the issue: I receive a HTTP Status 404 - Not Found error. I know it's because it's not finding the page, but after trying several solutions... I seem to not be able to find the piece of code that would make a difference... Any help would be much appreciated
The Controller Servlet:
package controller;
import cart.ShoppingCart;
import wishlist.Wishlist;
import entity.Category;
import entity.Product;
import java.io.IOException;
import java.util.Collection;
import javax.ejb.EJB;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import session.CategoryFacade;
import session.ProductFacade;
public class ControllerServlet extends HttpServlet {
#EJB
private CategoryFacade categoryFacade;
#EJB
private ProductFacade productFacade;
#Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userPath = request.getServletPath();
HttpSession session = request.getSession();
Category selectedCategory;
Product selectedProduct;
Collection<Product> categoryProducts;
// if product page is requested
if (userPath.equals("/product")) {
// get productId from request
String productId = request.getQueryString();
if (productId != null) {
// get selected product
selectedProduct = productFacade.find(Short.parseShort(productId));
// place selected product in session scope
session.setAttribute("selectedProduct", selectedProduct);
}
This is the code from the category.jsp to call the product:
<img class="img" src="${initParam.productImagePath}${product.name}.jpg">
Full Category.jsp:
<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
<c:forEach var="product" items="${categoryProducts}" varStatus="iter">
<td>
<tbody>
<tr>
<td
style="vertical-align: middle; width: 180px; text-align: center; height: 180px;"
class="cell"><img class="img" src="${initParam.productImagePath}${product.name}.jpg"><br>
</td>
<td
style="vertical-align: middle; width: 140px; text-align: center;">${product.name}<br>
</td>
<td
style="vertical-align: middle; width: 125px; text-align: center;">$
${product.price}<br>
</td>
<td
style="vertical-align: middle; width: 125px; text-align: center;">
<form action="addToWishlist" method="post"><br><br> <input
name="productId" value="${product.id}" type="hidden">
<input class="submit" value="<fmt:message key='AddToWishlist'/>" type="submit"> </form>
<br>
</td>
<td
style="vertical-align: middle; width: 123px; text-align: center;">
<form action="addToCart" method="post"><br><br>
<input name="productId"
value="${product.id}" type="hidden"> <input class="submit" value="<fmt:message key='AddToCart'/>"
type="submit">
</form>
<br>
</td>
</tr>
</tbody>
</c:forEach>
</table>
This is the Product.jsp (destination page):
<table style="text-align: left; width: 100%; height: 172px;" border="0"
cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td colspan="1" rowspan="6" style="vertical-align: top;">product_gallery<br>
</td>
<td colspan="1" rowspan="6" style="vertical-align: top;"><img class="img" src="${initParam.productBigImagePath}${product.name}.jpg"><br>
</td>
<td style="vertical-align: top;">${selectedProduct.name}<br>
</td>
<td style="vertical-align: top;"><br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">$ ${selectedProduct.price}</td>
<td style="vertical-align: top;"><br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><br>
</td>
<td style="vertical-align: top;"><br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><br>
</td>
<td style="vertical-align: top;"><br>
</td>
</tr>
<tr>
<td colspan="2" rowspan="1" style="vertical-align: top;">${selectedProduct.description}</td>
</tr>
<tr>
<td style="vertical-align: top;"><form action="addToWishlist" method="post"><br><br> <input
name="productId" value="${product.id}" type="hidden">
<input class="submit" value="<fmt:message key='AddToWishlist'/>" type="submit"> </form><br>
</td>
<td style="vertical-align: top;"><form action="addToCart" method="post"><br><br>
<input name="productId"
value="${product.id}" type="hidden"> <input class="submit" value="<fmt:message key='AddToCart'/>"
type="submit">
</form></td>
</tr>
<tr>
<td style="vertical-align: top;"><br>
</td>
<td style="vertical-align: top;"><br>
</td>
<td colspan="2" rowspan="1" style="vertical-align: top;"><ul><li style="background-color: rgb(198, 255, 201); width:100%; text-align:center; border-radius:2em;"><fmt:message key='ContinueShopping'/></li>
</ul><br>
</td>
</tr>
</tbody>
</table>
Solved the issue myself. I forgot to add the parameter in the web.xml:
<servlet-mapping>
<servlet-name>ControllerServlet</servlet-name>
<url-pattern>/product</url-pattern>
</servlet-mapping>
I have a list of category characterized by an ID in the database and I want when I choose some category "Catégorie" & insert his value in a checkbox, after click on save i want see this value in a table that contains all values exactly in his place.so to resume i want when i chose a category from list and insert his value see it in the table.Im working with JAVA EE & all this in a page JSP.
Im tried to resolve the problem by doing a test condition by recupere the value of the id category with request.getAttribute("iddd") and test if it equal to "0"(for example) but it doesn't work
<table border="1" id="testTable2" border="1" width=100% class="table table-hover">
<thead>
<tr align="center" >
<th width="50%">Postes</th>
<th>Poste1 (22h-06h)</th>
<th>Poste2 (06h-14h)</th>
<th>Poste3 (14h-22h)</th>
<th>Total Journé</th>
</tr>
</thead>
<%
UhtBeans stockss;
if(request.getAttribute("stock") != null){
stockss =(UhtBeans) request.getAttribute("stock");
}else {
Operation opers = new Operation();
stockss = new UhtBeans();
stockss.setListSt(opers.allStock());
}
%>
<%
request.setAttribute("iddd",opp.getAllIdCategorie());
Iterator<Stock> lists = stockss.getListSt().iterator();
while(lists.hasNext()){
Stock s =lists.next();
%>
<tr>
<th bgcolor="green" class="Date"><%=s.getDate() %></th>
</tr>
<tr align="center" bgcolor="cyan">
<th>DIAGRAMME TEMPS</th>
<th>Durée(min)</th>
<th>Durée(min)</th>
<th>Durée(min)</th>
<th>Durée(min)</th>
</tr>
<tbody id="colonne">
<tr align="center">
<th bgcolor="yellow">Temps Calendrier</th>
<%int d=480; %>
<th id="d" class="Duree"><%=d %></th>
<th ></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Temps non disponible</th>
<th class="Duree" id="d11"><%
System.out.println("ID DU CATEGORIE EST : "+request.getAttribute("iddd"));
if (request.getAttribute("iddd") == "0"){
%>
<input type="number" id="d1" class="form-control" value="<%=s.getDuree() %>">
<%} %>
</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps Disponible</th>
<%int d2;
d2=d; %>
<th><%=d2 %></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Temps disponible non utilisé</th>
<th class="Duree">
<%System.out.println("ID De TDNU EST : "+ request.getAttribute("iddd"));
if(request.getAttribute("iddd") == "1"){
%><%=s.getDuree()%>
<%} %>
</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps d'ouverture</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Préventif et révision équipement</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Autres arrêts planifiés non OP</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps operationnel</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Nettoyage</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Autres arrêts OP planifiés</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps de production</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Arrêts organisationnels</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Arrêts techniques</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Arrêts technologiques</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Running time</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps net de production</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<%
}
%>
</tbody>
</table>