Jsoup getElementsByClass gives size 0 Elements - java

I'm trying to write a program that fetches weather information from weather.com by using JSoup. This is what I have so far:
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.jsoup.Jsoup;
public class WeatherComHandler {
private Element ForeCastDiv;
public static void main(String[] args) {
WeatherComHandler wch = new WeatherComHandler("http://www.weather.com/weather/today/Brussels+BEXX0005:1:BE");
wch.getTodaysForeCast();
}
public WeatherComHandler(String url) {
getForeCastDiv(url);
}
private void getForeCastDiv(String url) {
try {
Document doc = Jsoup.connect(url).get();
ForeCastDiv = doc.getElementById("wx-forecast-container");
} catch(Exception e) {
e.getStackTrace();
}
}
public void getTodaysForeCast() {
System.out.println(ForeCastDiv.toString());
System.out.println(ForeCastDiv.hasClass("wx-data-part wx-first"));
Elements todaysElements = ForeCastDiv.getElementsByClass("wx-data-part wx-first");
System.out.println(todaysElements.size());
}
}
This is the output:
<div id="wx-forecast-container">
<div class="wx-today wx-module wx-grid3of6">
<div class="wx-title-container">
<h2 class="wx-title"><img src="http://i.imwx.com/common/My.png" /> Forecast for Today</h2>
<div class="wx-updated">
Updated: Oct 28, 5:45pm Local Time
</div>
<div class="wx-promo-links wx-cond wx-severe wx-severe-0">
<ul class="wx-links">
<li class="wx-icon wx-cond wx-desktop"> <a class="wx-icon wx-cond wx-desktop" href="/apps/desktop-weather" location="" from="today_promo_1" title="Weather on my Desktop">Desktop App</a> </li>
</ul>
</div>
</div>
<div class="wx-weather-details">
<div class="wx-timepart-title wx-first">
Right Now
<div class="wx-module wx-grid1of6 wx-weather wx-love-module wx-cond-bg">
<div class="wx-module-inner">
<div class="wx-icon wx-social wx-balloon-wt-lt wx-clickable wx-love-ugh" data-good="true" data-share-trx="" data-share-icon="http://s.imwx.com/img/common/social/lmw-love.jpg" title="Love My Weather" data-share-desc="It's 55°F, Clear">
<div class="wx-icon wx-social wx-heart"></div>
<h4 data-share-title="Love! Right now in Brussels, Belgium"></h4>
</div>
<div class="wx-icon wx-social wx-balloon-wt-rt wx-clickable wx-love-ugh" data-good="false" data-share-trx="" data-share-icon="http://s.imwx.com/img/common/social/lmw-ugg.jpg" title="Don't Love My Weather" data-share-desc="It's 55°F, Clear">
<h4 data-share-title="Ugh! Right now in Brussels, Belgium"></h4>
</div>
</div>
</div>
</div>
<div class="wx-timepart-title">
Earlier Today
</div>
<div class="wx-timepart-title">
Tonight
</div>
<div class="wx-data-part wx-first">
<img src="http://s.imwx.com/v.20131006.214956/img/wxicon/120/31.png" height="120" width="120" alt="Clear" class="wx-weather-icon" />
</div>
<div class="wx-data-part">
<img src="http://s.imwx.com/v.20131006.214956/img/wxicon/120/34.png" height="120" width="120" alt="Fair / Windy" class="wx-weather-icon" />
</div>
<div class="wx-data-part">
<img src="http://s.imwx.com/v.20131006.214956/img/wxicon/120/29.png" height="120" width="120" alt="Partly Cloudy" class="wx-weather-icon" />
</div>
<div class="wx-data-part wx-first">
<div class="wx-temperature">
<span itemprop="temperature-fahrenheit">55</span>
<span class="wx-degrees">°<span class="wx-unit">F</span></span>
</div>
<div class="wx-temperature-label">
FEELS LIKE
<span itemprop="feels-like-temperature-fahrenheit">55</span>°
</div>
</div>
<div class="wx-data-part">
<div class="wx-temperature">
62
<span class="wx-degrees">°</span>
</div>
<div class="wx-temperature-label">
HIGH AT 11:45 AM
</div>
</div>
<div class="wx-data-part">
<div class="wx-temperature">
47
<span class="wx-degrees">°</span>
</div>
<div class="wx-temperature-label">
LOW
</div>
</div>
<div class="wx-data-part wx-first">
<div class="wx-phrase ">
Clear
</div>
<div class="wx-obs-qualifier ">
<span class="wx-hide" itemprop="observation-qualifier">OQ1190</span>
<span class="wx-hide" itemprop="observation-qualifier-severity">2</span>
<span itemprop="observation-qualifier-phrase">Locations nearby are reporting rain with wind.</span>
</div>
</div>
<div class="wx-data-part">
<div class="wx-phrase ">
Fair / Windy
</div>
</div>
<div class="wx-data-part">
<div class="wx-phrase ">
Partly Cloudy
</div>
</div>
<div class="wx-data-part wx-first">
<h6 class="wx-label">Past 24-hr Precip:</h6>
<div class="wx-data">
0.34 in
<span class="wx-estimated">(est.)</span>
</div>
</div>
<div class="wx-data-part">
<h6 class="wx-label"></h6>
<div class="wx-data"></div>
</div>
<div class="wx-data-part">
<h6 class="wx-label">Chance of <span class="wx-firstletter">rain</span></h6>
<div class="wx-data">
<span class="wx-icon wx-raindrop"></span>20%
</div>
</div>
<div class="wx-collapsible">
<div class="wx-data-part wx-first wx-wind">
<h6 class="wx-label">Wind:</h6>
<div class="wx-data">
<div class="wx-icon wx-dir-arrow-sm wind-dir-SW"></div>
<div class="wx-wind-label">
SW at 17 mph
</div>
</div>
</div>
<div class="wx-data-part wx-wind">
<h6 class="wx-label"></h6>
<div class="wx-data">
<div class="wx-wind-label"></div>
</div>
</div>
<div class="wx-data-part wx-wind">
<h6 class="wx-label">Wind:</h6>
<div class="wx-data">
<div class="wx-icon wx-dir-arrow-sm wind-dir-SW"></div>
<div class="wx-wind-label">
SW at 18 mph
</div>
</div>
</div>
<div class="wx-data-part wx-first">
<h6 class="wx-label">Humidity:</h6>
<div class="wx-data">
76%
</div>
</div>
<div class="wx-data-part">
<h6 class="wx-label"></h6>
<div class="wx-data"></div>
</div>
<div class="wx-data-part">
<h6 class="wx-label">Humidity:</h6>
<div class="wx-data">
82%
</div>
</div>
<div class="wx-data-part wx-first">
<h6 class="wx-label">UV Index:</h6>
<div class="wx-data">
0 - Low
</div>
</div>
<div class="wx-data-part">
<h6 class="wx-label"></h6>
<div class="wx-data"></div>
</div>
<div class="wx-data-part"></div>
<div class="wx-data-part wx-first ">
<h6 class="wx-label"></h6>
<p class="wx-text"></p>
</div>
<div class="wx-data-part ">
<h6 class="wx-label"></h6>
<p class="wx-text"></p>
</div>
<div class="wx-data-part ">
<h6 class="wx-label">Tonight:</h6>
<p class="wx-text">Partly cloudy skies. Low 47F. Winds SW at 15 to 25 mph.</p>
</div>
<div class="wx-astro-neighbor">
<div class="wx-data-part wx-first">
<h6 class="wx-label">Pressure:</h6>
<div class="wx-data">
<span itemprop="barometric-pressure-incheshg"> 29.59 in </span>
<span class="wx-icon wx-dir-arrow-sm wx-pressure-steady"></span>
</div>
</div>
<div class="wx-data-part wx-first wx-dewpoint">
<h6 class="wx-label">Dew Point: <span class="wx-icon wx-long wx-info"> <i>Humidity becomes more noticeable as the dew point rises above 60°F. Readings above 75°F can feel stifling.</i> </span> </h6>
<div class="wx-data">
47°
</div>
</div>
<div class="wx-data-part wx-first">
<h6 class="wx-label">Visibility:</h6>
<div class="wx-data">
6.0 mi
</div>
</div>
</div>
<div class="wx-astro-details">
<h3 class="wx-astro-title">Sun & Moon</h3>
<dl class="wx-first">
<dt>
Sunrise:
</dt>
<dd>
7:28 am
</dd>
<dt>
Sunset:
</dt>
<dd>
5:25 pm
</dd>
</dl>
<dl>
<dt>
Moonrise:
</dt>
<dd>
12:27 am
</dd>
<dt>
Moonset:
</dt>
<dd>
2:32 pm
</dd>
</dl>
<dl class="wx-moonphase-container">
<dt>
Moonphase:
</dt>
<dd>
<div class="wx-icon wx-moonphase wx-moon-23"></div>
<div class="wx-moonphase-label">
Waning Crescent
</div>
</dd>
</dl>
</div>
</div>
</div>
<div class="wx-toggle-collapsible-container">
<div class="wx-toggle-collapsible wx-clickable">
<div class="wx-control wx-expand-control" tracktype="action" trackstr="today_rightnow_showmore">
<span class="wx-icon wx-arrow wx-mb-lg-dn"></span>Open Weather Details
</div>
<div class="wx-control wx-collapse-control wx-hide" tracktype="action" trackstr="today_rightnow_showless">
<span class="wx-icon wx-arrow wx-mb-lg-up"></span>Close Weather Details
</div>
</div>
</div>
<div class="wx-pagination-linkers">
<div class="wx-next-linker">
<ul class="wx-links">
<li class=""> <a class="" href="/weather/hourbyhour/graph/Brussels+BEXX0005:1:BE" location="" from="today_rightnow-Today_tempGraph_1" title="">Hourly Forecast</a> </li>
</ul>
</div>
</div>
</div>
<script>$("#wx-icon wx-long wx-info").attr('title','This is the hover-over text');</script>
<div id="wunderground-lightbox" class="wx-dialog">
<div class="wx-close" title="Close">
<div class="wx-icon"></div>
</div>
</div>
<div class="wx-combinedPromo wx-module wx-grid3of6">
<div class="wx-commuter-promo" data-classname="wx-grid-2" from="today-commuterpromo" data-layers="traffic,weather" data-locationinus="false" data-backgroundimageurl="" data-location-zoom="10" data-location-latitude="50.85045" data-location-longitude="4.34878">
<div class="wx-commute-promo-callout-title">
<div class="wx-titleIconHolder">
<img class="wx-titleIcon" src="http://s.imwx.com/img/module/TrafficCams_16x16.png" />
</div>
<div class="wx-titleText">
NEW! Traffic & Commuter Forecast
</div>
</div>
</div>
</div>
<div class="wx-clear"></div>
<div class="wx-scroll-tracking wx-scroll-pres" data-modulecode="ScrollTracking1_Today" data-location="BEXX0005:1:BE" data-groupname="weblocal"></div>
<div class="wx-free-title ">
<h3>Latest Stories</h3>
</div>
<div id="wx-rightnowsecond-container">
<div id="wx-rightnow-container">
<div class="wx-module wx-mod1 wx-corsican wx-1x155M wx-render-mode" id="mod_4" data-vr-zone="today_beta_Media_top2">
<div class="wx-inner" data-vr-contentbox=""></div>
</div>
<div class="wx-module wx-mod1 wx-corsican wx-1x155M wx-render-mode" id="mod_5" data-vr-zone="today_beta_Media_top1">
<div class="wx-inner" data-vr-contentbox=""></div>
</div>
</div>
<div class="wx-module wx-trending-stories wx-tabbed-content wx-grid2of6">
<div class="wx-inner">
<h2 class="wx-title">Most Popular</h2>
<ul class="wx-tabs" data-vr-zone="Most Popular">
<li class="wx-tab wx-active" data-tab="today" data-vr-contentbox="">Today</li>
<li class="wx-tab wx-clickable" data-tab="this_week" data-vr-contentbox="">This Week</li>
</ul>
<ul class="wx-tab-content" data-tab="today" data-vr-zone="Most Popular">
<li data-vr-contentbox="">Superstorm Sandy: Then and Now (EXCLUSIVE PHOTOS)</li>
<li data-vr-contentbox="">Eerie Nighttime Shots of Abandoned America</li>
<li data-vr-contentbox="">Astounding Fall Photos That Will Make You Say 'Wow!'</li>
<li data-vr-contentbox="">Nightmares Fear Factory: Terrified Reactions at Haunted House (PHOTOS)</li>
<li data-vr-contentbox="">The 15 Worst U.S. Cities for Asthma</li>
<li data-vr-contentbox="">Shocking End to Shark Attack <span class="wx-icon wx-video wx-trending-video"></span></li>
<li data-vr-contentbox="">Gigantic Hornets Are Breeding <span class="wx-icon wx-video wx-trending-video"></span></li>
<li data-vr-contentbox="">18-Foot WHAT? <span class="wx-icon wx-video wx-trending-video"></span></li>
</ul>
<ul class="wx-tab-content" data-tab="this_week" style="display:none;" data-vr-zone="Most Popular">
<li data-vr-contentbox="">Superstorm Sandy: Then and Now (EXCLUSIVE PHOTOS)</li>
<li data-vr-contentbox="">Nightmares Fear Factory: Terrified Reactions at Haunted House (PHOTOS)</li>
<li data-vr-contentbox="">Eerie Nighttime Shots of Abandoned America</li>
<li data-vr-contentbox="">8 Deadly Venomous Creatures and Those Who've Survived (PHOTOS)</li>
<li data-vr-contentbox="">Astounding Fall Photos That Will Make You Say 'Wow!'</li>
</ul>
</div>
</div>
</div>
<div class="wx-map wx-cc-map wx-grid3of6 wx-module pagelet " data-severelocation="false" data-location="BEXX0005" data-location-type="1" data-overlay="" data-zoom="" data-tropical="" data-mapsize="3" data-fragid="frag_newccMap_166739" data-modulecode="beta_CCMap" data-pageid="62288">
</div>
</div>
false
0
The problem is getTodaysForeCast() keeps saying that the size of todaysElements is 0, which it shouldn't be. Could anyone explain me why this is happening or what I'm doing wrong?
thanks in advance.

Jsoup will not accept two combined classes in the getElementsByClass method. Try something like:
Elements todaysElements = ForeCastDiv.getElementsByAttributeValueContaining("class", "wx-data-part wx-first");

You're passing two separate class names (separated by a space) to both hasClass() and getElementsByClass(), both of which can only handle one class at a time.
Try using select() instead. It allows you to use complex CSS selectors to find elements, like this:
ForeCastDiv.select(".wx-data-part.wx-first")

Related

How to fix a dynamic route

I'm just taking a vue3 project and need a bit of help with a dynamic route.
Firstly, I have a pet.json archive where I have information about dogs and cats. I'm gonna show you my project:
App.vue
<template>
<div id="app">
<app-header />
<div class="app-container">
<router-link to="{ id: PetDetail, params: { id: json.id, pet:pet }}"
><router-view
/></router-link>
</div>
<Footer />
</div>
</template>
<script>
import AppHeader from "#/components/AppHeader.vue";
import Footer from "#/components/Footer.vue";
export default {
name: "App",
components: {
AppHeader,
Footer,
},
};
</script>
route.js
import { createRouter, createWebHistory } from "vue-router";
import Home from "#/views/Home.vue";
import NotFound from "#/views/NotFound.vue";
import PetDetail from "#/components/PetDetail.vue";
const routes = [
{
path: "/",
name: "Home",
component: Home,
},
{
path: "/:catchAll(.*)",
name: "NotFound",
component: NotFound,
},
{
path: "/pet/:id?",
name: "PetDetail",
component: PetDetail,
},
];
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes,
});
export default router;
PetDetail.vue
<template>
<header id="header" class="header">
<div class="header-container_pet container">
<nav>
<a class="btn-icon logo-btn" href="/">
<img
class="logo logo-normal"
src="../assets/logo_white.svg"
alt="Logo petinder"
/>
<img
class="logo logo-white"
src="../assets/logo.svg"
alt="Logo petinder"
/>
</a>
<ul class="menu-links">
<li>Servicios</li>
<li>Sobre nosotros</li>
<li>Contactar</li>
</ul>
</nav>
<a href="" class="btn btn-login btn-light" title="Iniciar sesión"
>Iniciar sesión</a
>
<div id="menuIcon" class="menu-icon">
<div id="menuIconBar" class="menu-icon-bar"></div>
</div>
</div>
</header>
<main class="page-home">
<div class="container">
<div class="block-featured-content">
<div class="foto-pet">
<div class="foto-pet-color"></div>
</div>
<div class="pet-info">
<p class="pet-title">
Darko <span class="blue-text">5 años, Barcelona</span>
</p>
<div class="pet-details">
<div class="pet-detail">
<span class="pet-detail-title">Especie</span>
<span class="pet-detail-data">Perro</span>
</div>
<div class="pet-detail">
<span class="pet-detail-title">Sexo</span>
<span class="pet-detail-data">Macho</span>
</div>
<div class="pet-detail">
<span class="pet-detail-title">Medida</span>
<span class="pet-detail-data">Pequeño</span>
</div>
<div class="pet-detail">
<span class="pet-detail-title">Fecha de nacimiento</span>
<span class="pet-detail-data">08/10/2016</span>
</div>
<div class="pet-detail">
<span class="pet-detail-title">Estado</span>
<span class="pet-detail-data">En adopción</span>
</div>
</div>
<div class="buttom">
<div class="buttom-adoptar">
<p class="p-adoptar-text">Lo quiero adoptar</p>
</div>
<div class="buttom-compartir">
<p class="p-compartir-text">Compartir</p>
</div>
</div>
</div>
</div>
<div class="pet-history">
<h3 class="my-history">Mi historia</h3>
<p class="my-history-text">
Darko a sus 5 años de edad tiene que volver a buscar un hogar, su
dueña ingresaba y nadie se podía hacer cargo de él. Como buen Bulldog
Francés es muy bueno, cariñoso y sociable, pero a la vez cabezota y
obstinado, ideal para amantes de esta raza. Esperamos que Darko no
tenga que pasar mucho más tiempo en una jaula y por fin, encuentre esa
familia que lo cuide y quiera como se merece.
</p>
</div>
<div class="pet-extras">
<div class="pet-extra">
<h3 class="my-history">Mi personalidad</h3>
<div class="tags">
<span class="tag-blue">Bueno con otros perros</span>
<span class="tag-blue">Cariñoso</span>
<span class="tag-blue">A veces ladro</span>
<span class="tag-blue">Amigable con extraños</span>
</div>
</div>
<div class="pet-extra">
<h3 class="my-history">Me entregan</h3>
<div class="pet-details-extra">
<div class="pet-detail">
<span class="pet-detail-title">Vacunado</span>
<span class="tag-red">No</span>
</div>
<div class="pet-detail">
<span class="pet-detail-title">Desparasitado</span>
<span class="tag-green">Si</span>
</div>
<div class="pet-detail">
<span class="pet-detail-title">Esterilizado</span>
<span class="tag-green">Si</span>
</div>
<div class="pet-detail">
<span class="pet-detail-title">Microchip</span>
<span class="tag-green">Si</span>
</div>
</div>
</div>
<div class="pet-extra">
<h3 class="my-history">Tienes que saber</h3>
<div class="pet-details-extra">
<div class="pet-detail">
<span class="pet-detail-data">Estoy en tratamiento médico</span>
</div>
<div class="pet-detail">
<span class="pet-detail-data">Soy positivo en Leishmania</span>
</div>
</div>
</div>
</div>
</div>
<section class="block-actions">
<div class="container">
<div class="match-box">
<p class="match-text">
Si <b>Darko</b> ya ha sido adoptado/a o no hacéis match, tenemos
otros animales que te necesitan. Encuéntralos
</p>
<form class="search-bar">
<input
type="text"
placeholder="Busca a tu nuevo mejor amigo"
class="form-control search-control"
/>
<button type="submit" class="btn-icon search-button"></button>
</form>
</div>
</div>
</section>
</main>
</template>
<script>
import json from "#/pets.json";
export default {
name: "PetDetail",
data() {
return {
id: this.$route.params.id,
object: {},
};
},
mounted() {
this.object = json.objects.find((item) => item.id == this.$route.params.id);
},
};
</script>
<style scoped lang="scss"></style>
PetList.vue
<template>
<div class="container">
<h2 class="title">Últimas incorporaciones</h2>
<div class="row">
<div
class="col-sm-6 col-md-4 col-lg-3"
v-for="pet in pets"
:key="pet.name"
>
<article class="card">
<div class="card-header">
<img
class="card-img-top"
:src="pet.image_url"
alt="{{ pet.name }}"
/>
</div>
<div class="card-body">
<div class="card-main">
<!-- <h3 class="card-title">{{ pet.nom }}</h3> -->
<h3 class="card-title">{{ pet.name }}</h3>
<p class="card-text">{{ pet.location }}</p>
</div>
<ul class="card-icons">
<li>
<img
v-if="pet.species == 'Gato'"
class="card-icon"
src="../assets/icons/icon_cat.svg"
alt="{{ pet.species }}"
/>
<img
v-if="pet.species == 'Perro'"
class="card-icon"
src="../assets/icons/icon_dog.svg"
alt="{{ pet.species }}"
/>
</li>
<li>
<img
v-if="pet.sex == 'Macho'"
class="card-icon"
src="../assets/icons/icon_male.svg"
alt="{{ pet.sex }}"
/>
<img
v-if="pet.sex == 'Hembra'"
class="card-icon"
src="../assets/icons/icon_female.svg"
alt="{{ pet.sex }}"
/>
</li>
</ul>
</div>
</article>
</div>
</div>
</div>
</template>
<script>
import json from "#/pets.json";
export default {
name: "PetList",
data() {
return {
pets: json.data,
};
},
};
</script>
<style scoped lang="scss"></style>
pet.json
"data": [
{
"id": 1,
"name": "Thor",
"image_url": "https://petinder-images.netlify.app/thor.png",
"location": "Barcelona",
"species": "Gato",
"sex": "Macho",
"size": "Mediano",
"birth_date": "2018-06-01",
"handle_status": {
"vaccinated": false,
"dewormed": true,
"sterilized": true,
"microchip": true
},
"bio": "Thor llegó de Montcada y es algo tímido pero con un poco de confianza se deja mimar y acariciar.",
"status": "En adopción",
"personality": [
"Bueno con gatos",
"Timido",
"Juguetón"
],
"info_notes": []
},
PetList.vue prints all pet cards in home page. And I need click on each pet to go to their card using his id.
I don't know where is my problem but for sure I'm not calling good the route link.

Simplifying Complex XPath Expression in Selenium

I have the following HTML snippet:
<div class="a-row a-spacing-micro">
<div class="a-column a-span4 a-spacing-none a-spacing-top-mini address-column">
<div id="ya-myab-display-address-block-2" class="a-box a-spacing-none normal-desktop-address-tile">
<div class="a-box-inner a-padding-none">
<div class="a-section address-section-no-default">
<div class="a-row a-spacing-small">
<ul class="a-unordered-list a-noStyle a-vertical">
<li>
<span class="a-list-item">
<h5 id="address-ui-widgets-FullName" class="id-addr-ux-search-text a-text-bold">XXX XXXXX</h5>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-AddressLineOne" class="id-addr-ux-search-text">DDD XXXX XX</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-CityXXatePoXXalCode" class="id-addr-ux-search-text">XXXXXXXX, XX DDDDD-DDDD</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-Country" class="id-addr-ux-search-text">United States</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-PhoneNumber" class="id-addr-ux-search-text">Phone number: DDDDDDDDDD</span>
</span>
</li>
</ul>
<script>P.when('A', 'ready').execute(function(A) { var $ = A.$; var localizedXXrings = A.XXate('address-ui-widgets-XXore-map-text-id'); $(".address-ui-widgets-map-link").click(function(event) { event.preventDefault(); window.open(this.href, localizedXXrings["address_ui_widgets_XXore_address_map_header"], "width=600,height=450"); }) }); </script>
</div>
</div>
</div>
</div>
<div id="ya-myab-edit-address-desktop-row-2" class="a-row edit-address-desktop-link">
<a id="ya-myab-address-edit-btn-2" class="a-link-normal" href="/a/addresses/edit?ref=ya_address_book_edit_button&addressID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX">Edit </a>
|
<a id="ya-myab-address-delete-btn-2" class="a-link-normal" href="#">
<span class="a-declarative" data-a-modal="{"name":"deleteAddressModal-2","width":"400","header":"Confirm Deletion"}" data-action="a-modal">Delete</span>
<div id="a-popover-deleteAddressModal-2" class="a-popover-preload">
<div class="a-section">
<div class="a-row a-spacing-small">
<ul class="a-unordered-list a-noStyle a-vertical">
<li>
<span class="a-list-item">
<h5 id="address-ui-widgets-FullName" class="id-addr-ux-search-text a-text-bold">XXX XXXXX</h5>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-AddressLineOne" class="id-addr-ux-search-text">DDD XXXX XX</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-CityXXatePoXXalCode" class="id-addr-ux-search-text">XXXXXXXX, XX DDDDD-DDDD</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-Country" class="id-addr-ux-search-text">United States</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-PhoneNumber" class="id-addr-ux-search-text">Phone number: 3472631425</span>
</span>
</li>
</ul>
<script>P.when('A', 'ready').execute(function(A) { var $ = A.$; var localizedXXrings = A.XXate('address-ui-widgets-XXore-map-text-id'); $(".address-ui-widgets-map-link").click(function(event) { event.preventDefault(); window.open(this.href, localizedXXrings["address_ui_widgets_XXore_address_map_header"], "width=600,height=450"); }) }); </script>
</div>
<div class="a-row a-spacing-small">
<span class="a-size-small a-color-tertiary">
<span class="a-text-bold">Please note: </span>
Deleting this address will not delete any pending orders being shipped to this address. To ensure uninterrupted fulfillment of future orders, please update any wishliXXs, subscribe and save settings and periodical subscriptions using this address.
</span>
</div>
<div class="a-row a-spacing-none">
<hr class="a-divider-normal"/>
</div>
<div class="a-row">
<div class="a-column a-span6">
<div class="a-row">
<div class="a-column a-span3"/>
<div class="a-column a-span8">
<span id="deleteAddressModal-2-cancel-btn" class="a-button a-button-span12">
<span class="a-button-inner">
<button id="deleteAddressModal-2-cancel-btn-announce" class="a-button-text" type="button">No</button>
</span>
</span>
</div>
</div>
</div>
<div class="a-column a-span6 a-span-laXX">
<div class="a-row">
<div class="a-column a-span1"/>
<div class="a-column a-span8">
<form class="a-spacing-none" action="/a/addresses/delete" method="poXX">
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" name="addressID"/>
<input type="hidden" value="false" name="isXXoreAddress"/>
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXX" name="csrfToken"/>
<span id="deleteAddressModal-2-submit-btn" class="a-button a-button-span12 a-button-primary">
<span class="a-button-inner">
<input class="a-button-input" type="submit" aria-labelledby="deleteAddressModal-2-submit-btn-announce"/>
<span id="deleteAddressModal-2-submit-btn-announce" class="a-button-text" aria-hidden="true">Yes</span>
</span>
</span>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</a>
<form class="set-address-default" action="/a/addresses/set-default-address?ref=ya_address_book_set_default_button" method="poXX">
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXX" name="csrfToken"/>
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" name="addressID"/>
|
<a id="ya-myab-set-default-shipping-btn-2" class="a-link-normal" href="#">Set as Default</a>
</form>
</div>
</div>
<div class="a-column a-span4 a-spacing-none a-spacing-top-mini address-column">
<div id="ya-myab-display-address-block-3" class="a-box a-spacing-none normal-desktop-address-tile">
<div class="a-box-inner a-padding-none">
<div class="a-section address-section-no-default">
<div class="a-row a-spacing-small">
<ul class="a-unordered-list a-noStyle a-vertical">
<li>
<span class="a-list-item">
<h5 id="address-ui-widgets-FullName" class="id-addr-ux-search-text a-text-bold">XXXXXXX XXXXX</h5>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-AddressLineOne" class="id-addr-ux-search-text">DDD XXXX XX</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-CityXXatePoXXalCode" class="id-addr-ux-search-text">XXXXXXXX, XX DDDDD</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-Country" class="id-addr-ux-search-text">United States</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-PhoneNumber" class="id-addr-ux-search-text">Phone number: 3472631425</span>
</span>
</li>
</ul>
<script>P.when('A', 'ready').execute(function(A) { var $ = A.$; var localizedXXrings = A.XXate('address-ui-widgets-XXore-map-text-id'); $(".address-ui-widgets-map-link").click(function(event) { event.preventDefault(); window.open(this.href, localizedXXrings["address_ui_widgets_XXore_address_map_header"], "width=600,height=450"); }) }); </script>
</div>
</div>
</div>
</div>
<div id="ya-myab-edit-address-desktop-row-3" class="a-row edit-address-desktop-link">
<a id="ya-myab-address-edit-btn-3" class="a-link-normal" href="/a/addresses/edit?ref=ya_address_book_edit_button&addressID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX">Edit </a>
|
<a id="ya-myab-address-delete-btn-3" class="a-link-normal" href="#">
<span class="a-declarative" data-a-modal="{"name":"deleteAddressModal-3","width":"400","header":"Confirm Deletion"}" data-action="a-modal">Delete</span>
<div id="a-popover-deleteAddressModal-3" class="a-popover-preload">
<div class="a-section">
<div class="a-row a-spacing-small">
<ul class="a-unordered-list a-noStyle a-vertical">
<li>
<span class="a-list-item">
<h5 id="address-ui-widgets-FullName" class="id-addr-ux-search-text a-text-bold">XXXXXXX XXXXX</h5>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-AddressLineOne" class="id-addr-ux-search-text">DDD XXXX XX</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-CityXXatePoXXalCode" class="id-addr-ux-search-text">XXXXXXXX, XX DDDDD</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-Country" class="id-addr-ux-search-text">United States</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-PhoneNumber" class="id-addr-ux-search-text">Phone number: DDDDDDDDDD</span>
</span>
</li>
</ul>
<script>P.when('A', 'ready').execute(function(A) { var $ = A.$; var localizedXXrings = A.XXate('address-ui-widgets-XXore-map-text-id'); $(".address-ui-widgets-map-link").click(function(event) { event.preventDefault(); window.open(this.href, localizedXXrings["address_ui_widgets_XXore_address_map_header"], "width=600,height=450"); }) }); </script>
</div>
<div class="a-row a-spacing-small">
<span class="a-size-small a-color-tertiary">
<span class="a-text-bold">Please note: </span>
Deleting this address will not delete any pending orders being shipped to this address. To ensure uninterrupted fulfillment of future orders, please update any wishliXXs, subscribe and save settings and periodical subscriptions using this address.
</span>
</div>
<div class="a-row a-spacing-none">
<hr class="a-divider-normal"/>
</div>
<div class="a-row">
<div class="a-column a-span6">
<div class="a-row">
<div class="a-column a-span3"/>
<div class="a-column a-span8">
<span id="deleteAddressModal-3-cancel-btn" class="a-button a-button-span12">
<span class="a-button-inner">
<button id="deleteAddressModal-3-cancel-btn-announce" class="a-button-text" type="button">No</button>
</span>
</span>
</div>
</div>
</div>
<div class="a-column a-span6 a-span-laXX">
<div class="a-row">
<div class="a-column a-span1"/>
<div class="a-column a-span8">
<form class="a-spacing-none" action="/a/addresses/delete" method="poXX">
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" name="addressID"/>
<input type="hidden" value="false" name="isXXoreAddress"/>
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXX" name="csrfToken"/>
<span id="deleteAddressModal-3-submit-btn" class="a-button a-button-span12 a-button-primary">
<span class="a-button-inner">
<input class="a-button-input" type="submit" aria-labelledby="deleteAddressModal-3-submit-btn-announce"/>
<span id="deleteAddressModal-3-submit-btn-announce" class="a-button-text" aria-hidden="true">Yes</span>
</span>
</span>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</a>
<form class="set-address-default" action="/a/addresses/set-default-address?ref=ya_address_book_set_default_button" method="poXX">
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXX" name="csrfToken"/>
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" name="addressID"/>
|
<a id="ya-myab-set-default-shipping-btn-3" class="a-link-normal" href="#">Set as Default</a>
</form>
</div>
</div>
<div class="a-column a-span4 a-spacing-none a-spacing-top-mini address-column a-span-laXX">
<div id="ya-myab-display-address-block-4" class="a-box a-spacing-none normal-desktop-address-tile">
<div class="a-box-inner a-padding-none">
<div class="a-section address-section-no-default">
<div class="a-row a-spacing-small">
<ul class="a-unordered-list a-noStyle a-vertical">
<li>
<span class="a-list-item">
<h5 id="address-ui-widgets-FullName" class="id-addr-ux-search-text a-text-bold">XXXXXXX XXXXX</h5>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-AddressLineOne" class="id-addr-ux-search-text">DDD XXXX XX</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-CityXXatePoXXalCode" class="id-addr-ux-search-text">XXXXXXXX, XX DDDDD</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-Country" class="id-addr-ux-search-text">United States</span>
</span>
</li>
</ul>
<script>P.when('A', 'ready').execute(function(A) { var $ = A.$; var localizedXXrings = A.XXate('address-ui-widgets-XXore-map-text-id'); $(".address-ui-widgets-map-link").click(function(event) { event.preventDefault(); window.open(this.href, localizedXXrings["address_ui_widgets_XXore_address_map_header"], "width=600,height=450"); }) }); </script>
</div>
</div>
</div>
</div>
<div id="ya-myab-edit-address-desktop-row-4" class="a-row edit-address-desktop-link">
<a id="ya-myab-address-edit-btn-4" class="a-link-normal" href="/a/addresses/edit?ref=ya_address_book_edit_button&addressID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX">Edit </a>
|
<a id="ya-myab-address-delete-btn-4" class="a-link-normal" href="#">
<span class="a-declarative" data-a-modal="{"name":"deleteAddressModal-4","width":"400","header":"Confirm Deletion"}" data-action="a-modal">Delete</span>
<div id="a-popover-deleteAddressModal-4" class="a-popover-preload">
<div class="a-section">
<div class="a-row a-spacing-small">
<ul class="a-unordered-list a-noStyle a-vertical">
<li>
<span class="a-list-item">
<h5 id="address-ui-widgets-FullName" class="id-addr-ux-search-text a-text-bold">XXXXXXX XXXXX</h5>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-AddressLineOne" class="id-addr-ux-search-text">DDD XXXX XX</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-CityXXatePoXXalCode" class="id-addr-ux-search-text">XXXXXXXX, XX DDDDD</span>
</span>
</li>
<li>
<span class="a-list-item">
<span id="address-ui-widgets-Country" class="id-addr-ux-search-text">United States</span>
</span>
</li>
</ul>
<script>P.when('A', 'ready').execute(function(A) { var $ = A.$; var localizedXXrings = A.XXate('address-ui-widgets-XXore-map-text-id'); $(".address-ui-widgets-map-link").click(function(event) { event.preventDefault(); window.open(this.href, localizedXXrings["address_ui_widgets_XXore_address_map_header"], "width=600,height=450"); }) }); </script>
</div>
<div class="a-row a-spacing-small">
<span class="a-size-small a-color-tertiary">
<span class="a-text-bold">Please note: </span>
Deleting this address will not delete any pending orders being shipped to this address. To ensure uninterrupted fulfillment of future orders, please update any wishliXXs, subscribe and save settings and periodical subscriptions using this address.
</span>
</div>
<div class="a-row a-spacing-none">
<hr class="a-divider-normal"/>
</div>
<div class="a-row">
<div class="a-column a-span6">
<div class="a-row">
<div class="a-column a-span3"/>
<div class="a-column a-span8">
<span id="deleteAddressModal-4-cancel-btn" class="a-button a-button-span12">
<span class="a-button-inner">
<button id="deleteAddressModal-4-cancel-btn-announce" class="a-button-text" type="button">No</button>
</span>
</span>
</div>
</div>
</div>
<div class="a-column a-span6 a-span-laXX">
<div class="a-row">
<div class="a-column a-span1"/>
<div class="a-column a-span8">
<form class="a-spacing-none" action="/a/addresses/delete" method="poXX">
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" name="addressID"/>
<input type="hidden" value="false" name="isXXoreAddress"/>
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXX" name="csrfToken"/>
<span id="deleteAddressModal-4-submit-btn" class="a-button a-button-span12 a-button-primary">
<span class="a-button-inner">
<input class="a-button-input" type="submit" aria-labelledby="deleteAddressModal-4-submit-btn-announce"/>
<span id="deleteAddressModal-4-submit-btn-announce" class="a-button-text" aria-hidden="true">Yes</span>
</span>
</span>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</a>
<form class="set-address-default" action="/a/addresses/set-default-address?ref=ya_address_book_set_default_button" method="poXX">
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXX" name="csrfToken"/>
<input type="hidden" value="XXXXXXXXXXXXXXXXXXXXXXX" name="addressID"/>
|
<a id="ya-myab-set-default-shipping-btn-4" class="a-link-normal" href="#">Set as Default</a>
</form>
</div>
</div>
</div>
Which roughly corresponds to the following layout/design:
As seen in above image, each box contains a name and address with the option to Edit, Delete or Set as Default.
Given only the address or name - how can I click "Set as Default" for the corresponding address (or name)?
So far the only working XPath is based on chaining several /parent::*/ expressions as seen below.
.//*[contains (text(),'123 XYZ AVE')]/parent::*/parent::*/parent::*/parent::*/parent::*/parent::*/parent::*/parent::*/form/input (selects based on address)
.//*[contains (text(),'NAME')]/parent::*/parent::*/parent::*/parent::*/parent::*/parent::*/parent::*/parent::*/form/input (selects based on name)
What the previous expressions do is they tell Selenium to find the name or address (.//*[contains (text(),'NAME')]) and then move up/backwards several levels until reaching the element that contains all child elements (which includes the Edit, Delete and Set as Default options) and then find the element with /form/input value.
While this works, it is awfully large and unwieldy and prone to break if the structure/number of any of the parent elements change.
How can I simplify this expression so that given an address or name (assuming all addresses/names are unique) I could identify and click the related "Set as Default" option without climbing up the hierarchy?
Thanks!
Firstly find the whole address section belongs to one person by person name, then find Edit/Delete/Set as Default button inside the section:
private WebElement findAddressSection(customerName) {
String xpathExp = "//div[contains(#class, 'a-column a-span4')]" +
"[div//h5[text()='"+ customerName+"']]";
return driver.findElement(By.xpath(xpathExp));
}
public void clickAddressEditBtn(customerName) {
WebElement section = findAddressSection(customerName);
section.findElement(By.cssSelector("a[id*='ya-myab-address-edit-btn']"))
.click();
}
public void clickAddressDeleteBtn(customerName) {
WebElement section = findAddressSection(customerName);
section.findElement(By.cssSelector("a[id*='ya-myab-address-delete-btn']"))
.click();
}
public void clickAddressSetDefaultBtn(customerName) {
WebElement section = findAddressSection(customerName);
section.findElement(By.cssSelector("a[id*='ya-myab-set-default-shipping-btn']"))
.click();
}
The sample HTML contains several errors (duplicate IDs, etc.), but the xpath below should help to get the value
'//*[contains(.,"abcdert")]/descendant::form/input'

Freemarker wrong page view

I meet a problem.
I download Bootstrap design for my project. When I unzip design to package and run a page everything is displayed correctly.
Then I copy html's pages and resources(css, js, images) to my project. Then I refactor index.html to index.ftl and run my project, the index page displayed a wrong view.
I haven't got any errors and warnings in Console and Network(in Chrome).
Freemarker can't displayed page correctly?
MainController.java
#Controller
public class MainController {
#Autowired
CategoryService categoryService;
#RequestMapping("/")
public String home() {
return "redirect:/index";
}
#RequestMapping("/index")
public String showIndex(Model model) {
model.addAttribute("categories", categoryService.getAllMainCategories());
return "index";
}
}
index.html (and .ftl)
<!DOCTYPE html>
<html>
<head>
<title>Grocery Store | Home</title>
<!-- for-mobile-apps -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- //for-mobile-apps -->
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<!-- font-awesome icons -->
<link href="css/font-awesome.css" rel="stylesheet" type="text/css" media="all" />
<!-- //font-awesome icons -->
<!-- js -->
<script src="js/jquery-1.11.1.min.js"></script>
<!-- //js -->
<link href='//fonts.googleapis.com/css?family=Ubuntu:400,300,300italic,400italic,500,500italic,700,700italic' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic' rel='stylesheet' type='text/css'>
<!-- start-smoth-scrolling -->
<script type="text/javascript" src="js/move-top.js"></script>
<script type="text/javascript" src="js/easing.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".scroll").click(function(event){
event.preventDefault();
$('html,body').animate({scrollTop:$(this.hash).offset().top},1000);
});
});
</script>
<!-- start-smoth-scrolling -->
</head>
<body>
<!-- header -->
<div class="agileits_header">
<div class="w3l_offers">
Today's special Offers !
</div>
<div class="w3l_search">
<form action="#" method="post">
<input type="text" name="Product" value="Search a product..." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Search a product...';}" required="">
<input type="submit" value=" ">
</form>
</div>
<div class="product_list_header">
<form action="#" method="post" class="last">
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="display" value="1" />
<input type="submit" name="submit" value="View your cart" class="button" />
</fieldset>
</form>
</div>
<div class="w3l_header_right">
<ul>
<li class="dropdown profile_details_drop">
<i class="fa fa-user" aria-hidden="true"></i><span class="caret"></span>
<div class="mega-dropdown-menu">
<div class="w3ls_vegetables">
<ul class="dropdown-menu drp-mnu">
<li>Login</li>
<li>Sign Up</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
<div class="w3l_header_right1">
<h2>Contact Us</h2>
</div>
<div class="clearfix"> </div>
</div>
<!-- script-for sticky-nav -->
<script>
$(document).ready(function() {
var navoffeset=$(".agileits_header").offset().top;
$(window).scroll(function(){
var scrollpos=$(window).scrollTop();
if(scrollpos >=navoffeset){
$(".agileits_header").addClass("fixed");
}else{
$(".agileits_header").removeClass("fixed");
}
});
});
</script>
<!-- //script-for sticky-nav -->
<div class="logo_products">
<div class="container">
<div class="w3ls_logo_products_left">
<h1><span>Grocery</span> Store</h1>
</div>
<div class="w3ls_logo_products_left1">
<ul class="special_items">
<li>Events<i>/</i></li>
<li>About Us<i>/</i></li>
<li>Best Deals<i>/</i></li>
<li>Services</li>
</ul>
</div>
<div class="w3ls_logo_products_left1">
<ul class="phone_email">
<li><i class="fa fa-phone" aria-hidden="true"></i>(+0123) 234 567</li>
<li><i class="fa fa-envelope-o" aria-hidden="true"></i>store#grocery.com</li>
</ul>
</div>
<div class="clearfix"> </div>
</div>
</div>
<!-- //header -->
<!-- banner -->
<div class="banner">
<div class="w3l_banner_nav_left">
<nav class="navbar nav_bottom">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header nav_2">
<button type="button" class="navbar-toggle collapsed navbar-toggle1" data-toggle="collapse" data-target="#bs-megadropdown-tabs">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-megadropdown-tabs">
<ul class="nav navbar-nav nav_1">
<li>Branded Foods</li>
<li>Households</li>
<li class="dropdown mega-dropdown active">
Veggies & Fruits<span class="caret"></span>
<div class="dropdown-menu mega-dropdown-menu w3ls_vegetables_menu">
<div class="w3ls_vegetables">
<ul>
<li>Vegetables</li>
<li>Fruits</li>
</ul>
</div>
</div>
</li>
<li>Kitchen</li>
<li>Short Codes</li>
<li class="dropdown">
Beverages<span class="caret"></span>
<div class="dropdown-menu mega-dropdown-menu w3ls_vegetables_menu">
<div class="w3ls_vegetables">
<ul>
<li>Soft Drinks</li>
<li>Juices</li>
</ul>
</div>
</div>
</li>
<li>Pet Food</li>
<li class="dropdown">
Frozen Foods<span class="caret"></span>
<div class="dropdown-menu mega-dropdown-menu w3ls_vegetables_menu">
<div class="w3ls_vegetables">
<ul>
<li>Frozen Snacks</li>
<li>Frozen Nonveg</li>
</ul>
</div>
</div>
</li>
<li>Bread & Bakery</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</div>
<div class="w3l_banner_nav_right">
<section class="slider">
<div class="flexslider">
<ul class="slides">
<li>
<div class="w3l_banner_nav_right_banner">
<h3>Make your <span>food</span> with Spicy.</h3>
<div class="more">
Shop now
</div>
</div>
</li>
<li>
<div class="w3l_banner_nav_right_banner1">
<h3>Make your <span>food</span> with Spicy.</h3>
<div class="more">
Shop now
</div>
</div>
</li>
<li>
<div class="w3l_banner_nav_right_banner2">
<h3>upto <i>50%</i> off.</h3>
<div class="more">
Shop now
</div>
</div>
</li>
</ul>
</div>
</section>
<!-- flexSlider -->
<link rel="stylesheet" href="css/flexslider.css" type="text/css" media="screen" property="" />
<script defer src="js/jquery.flexslider.js"></script>
<script type="text/javascript">
$(window).load(function(){
$('.flexslider').flexslider({
animation: "slide",
start: function(slider){
$('body').removeClass('loading');
}
});
});
</script>
<!-- //flexSlider -->
</div>
<div class="clearfix"></div>
</div>
<!-- banner -->
<div class="banner_bottom">
<div class="wthree_banner_bottom_left_grid_sub">
</div>
<div class="wthree_banner_bottom_left_grid_sub1">
<div class="col-md-4 wthree_banner_bottom_left">
<div class="wthree_banner_bottom_left_grid">
<img src="images/4.jpg" alt=" " class="img-responsive" />
<div class="wthree_banner_bottom_left_grid_pos">
<h4>Discount Offer <span>25%</span></h4>
</div>
</div>
</div>
<div class="col-md-4 wthree_banner_bottom_left">
<div class="wthree_banner_bottom_left_grid">
<img src="images/5.jpg" alt=" " class="img-responsive" />
<div class="wthree_banner_btm_pos">
<h3>introducing <span>best store</span> for <i>groceries</i></h3>
</div>
</div>
</div>
<div class="col-md-4 wthree_banner_bottom_left">
<div class="wthree_banner_bottom_left_grid">
<img src="images/6.jpg" alt=" " class="img-responsive" />
<div class="wthree_banner_btm_pos1">
<h3>Save <span>Upto</span> $10</h3>
</div>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</div>
<!-- top-brands -->
<div class="top-brands">
<div class="container">
<h3>Hot Offers</h3>
<div class="agile_top_brands_grids">
<div class="col-md-3 top_brand_left">
<div class="hover14 column">
<div class="agile_top_brand_left_grid">
<div class="tag"><img src="images/tag.png" alt=" " class="img-responsive" /></div>
<div class="agile_top_brand_left_grid1">
<figure>
<div class="snipcart-item block" >
<div class="snipcart-thumb">
<img title=" " alt=" " src="images/1.png" />
<p>fortune sunflower oil</p>
<h4>$7.99 <span>$10.00</span></h4>
</div>
<div class="snipcart-details top_brand_home_details">
<form action="checkout.html" method="post">
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value=" " />
<input type="hidden" name="item_name" value="Fortune Sunflower Oil" />
<input type="hidden" name="amount" value="7.99" />
<input type="hidden" name="discount_amount" value="1.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="return" value=" " />
<input type="hidden" name="cancel_return" value=" " />
<input type="submit" name="submit" value="Add to cart" class="button" />
</fieldset>
</form>
</div>
</div>
</figure>
</div>
</div>
</div>
</div>
<div class="col-md-3 top_brand_left">
<div class="hover14 column">
<div class="agile_top_brand_left_grid">
<div class="agile_top_brand_left_grid1">
<figure>
<div class="snipcart-item block" >
<div class="snipcart-thumb">
<img title=" " alt=" " src="images/3.png" />
<p>basmati rise (5 Kg)</p>
<h4>$11.99 <span>$15.00</span></h4>
</div>
<div class="snipcart-details top_brand_home_details">
<form action="#" method="post">
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value=" " />
<input type="hidden" name="item_name" value="basmati rise" />
<input type="hidden" name="amount" value="11.99" />
<input type="hidden" name="discount_amount" value="1.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="return" value=" " />
<input type="hidden" name="cancel_return" value=" " />
<input type="submit" name="submit" value="Add to cart" class="button" />
</fieldset>
</form>
</div>
</div>
</figure>
</div>
</div>
</div>
</div>
<div class="col-md-3 top_brand_left">
<div class="hover14 column">
<div class="agile_top_brand_left_grid">
<div class="agile_top_brand_left_grid_pos">
<img src="images/offer.png" alt=" " class="img-responsive" />
</div>
<div class="agile_top_brand_left_grid1">
<figure>
<div class="snipcart-item block">
<div class="snipcart-thumb">
<img src="images/2.png" alt=" " class="img-responsive" />
<p>Pepsi soft drink (2 Ltr)</p>
<h4>$8.00 <span>$10.00</span></h4>
</div>
<div class="snipcart-details top_brand_home_details">
<form action="#" method="post">
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value=" " />
<input type="hidden" name="item_name" value="Pepsi soft drink" />
<input type="hidden" name="amount" value="8.00" />
<input type="hidden" name="discount_amount" value="1.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="return" value=" " />
<input type="hidden" name="cancel_return" value=" " />
<input type="submit" name="submit" value="Add to cart" class="button" />
</fieldset>
</form>
</div>
</div>
</figure>
</div>
</div>
</div>
</div>
<div class="col-md-3 top_brand_left">
<div class="hover14 column">
<div class="agile_top_brand_left_grid">
<div class="agile_top_brand_left_grid_pos">
<img src="images/offer.png" alt=" " class="img-responsive" />
</div>
<div class="agile_top_brand_left_grid1">
<figure>
<div class="snipcart-item block">
<div class="snipcart-thumb">
<img src="images/4.png" alt=" " class="img-responsive" />
<p>dogs food (4 Kg)</p>
<h4>$9.00 <span>$11.00</span></h4>
</div>
<div class="snipcart-details top_brand_home_details">
<form action="#" method="post">
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value=" " />
<input type="hidden" name="item_name" value="dogs food" />
<input type="hidden" name="amount" value="9.00" />
<input type="hidden" name="discount_amount" value="1.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="return" value=" " />
<input type="hidden" name="cancel_return" value=" " />
<input type="submit" name="submit" value="Add to cart" class="button" />
</fieldset>
</form>
</div>
</div>
</figure>
</div>
</div>
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
<!-- //top-brands -->
<!-- fresh-vegetables -->
<div class="fresh-vegetables">
<div class="container">
<h3>Top Products</h3>
<div class="w3l_fresh_vegetables_grids">
<div class="col-md-3 w3l_fresh_vegetables_grid w3l_fresh_vegetables_grid_left">
<div class="w3l_fresh_vegetables_grid2">
<ul>
<li><i class="fa fa-check" aria-hidden="true"></i>All Brands</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Vegetables</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Fruits</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Juices</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Pet Food</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Bread & Bakery</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Cleaning</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Spices</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Dry Fruits</li>
<li><i class="fa fa-check" aria-hidden="true"></i>Dairy Products</li>
</ul>
</div>
</div>
<div class="col-md-9 w3l_fresh_vegetables_grid_right">
<div class="col-md-4 w3l_fresh_vegetables_grid">
<div class="w3l_fresh_vegetables_grid1">
<img src="images/8.jpg" alt=" " class="img-responsive" />
</div>
</div>
<div class="col-md-4 w3l_fresh_vegetables_grid">
<div class="w3l_fresh_vegetables_grid1">
<div class="w3l_fresh_vegetables_grid1_rel">
<img src="images/7.jpg" alt=" " class="img-responsive" />
<div class="w3l_fresh_vegetables_grid1_rel_pos">
<div class="more m1">
Shop now
</div>
</div>
</div>
</div>
<div class="w3l_fresh_vegetables_grid1_bottom">
<img src="images/10.jpg" alt=" " class="img-responsive" />
<div class="w3l_fresh_vegetables_grid1_bottom_pos">
<h5>Special Offers</h5>
</div>
</div>
</div>
<div class="col-md-4 w3l_fresh_vegetables_grid">
<div class="w3l_fresh_vegetables_grid1">
<img src="images/9.jpg" alt=" " class="img-responsive" />
</div>
<div class="w3l_fresh_vegetables_grid1_bottom">
<img src="images/11.jpg" alt=" " class="img-responsive" />
</div>
</div>
<div class="clearfix"> </div>
<div class="agileinfo_move_text">
<div class="agileinfo_marquee">
<h4>get <span class="blink_me">25% off</span> on first order and also get gift voucher</h4>
</div>
<div class="agileinfo_breaking_news">
<span> </span>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
<!-- //fresh-vegetables -->
<!-- newsletter -->
<div class="newsletter">
<div class="container">
<div class="w3agile_newsletter_left">
<h3>sign up for our newsletter</h3>
</div>
<div class="w3agile_newsletter_right">
<form action="#" method="post">
<input type="email" name="Email" value="Email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';}" required="">
<input type="submit" value="subscribe now">
</form>
</div>
<div class="clearfix"> </div>
</div>
</div>
<!-- //newsletter -->
<!-- footer -->
<div class="footer">
<div class="container">
<div class="col-md-3 w3_footer_grid">
<h3>information</h3>
<ul class="w3_footer_grid_list">
<li>Events</li>
<li>About Us</li>
<li>Best Deals</li>
<li>Services</li>
<li>Short Codes</li>
</ul>
</div>
<div class="col-md-3 w3_footer_grid">
<h3>policy info</h3>
<ul class="w3_footer_grid_list">
<li>FAQ</li>
<li>privacy policy</li>
<li>terms of use</li>
</ul>
</div>
<div class="col-md-3 w3_footer_grid">
<h3>what in stores</h3>
<ul class="w3_footer_grid_list">
<li>Pet Food</li>
<li>Frozen Snacks</li>
<li>Kitchen</li>
<li>Branded Foods</li>
<li>Households</li>
</ul>
</div>
<div class="col-md-3 w3_footer_grid">
<h3>twitter posts</h3>
<ul class="w3_footer_grid_list1">
<li><label class="fa fa-twitter" aria-hidden="true"></label><i>01 day ago</i><span>Non numquam http://sd.ds/13jklf#
eius modi tempora incidunt ut labore et
http://sd.ds/1389kjklf#quo nulla.</span></li>
<li><label class="fa fa-twitter" aria-hidden="true"></label><i>02 day ago</i><span>Con numquam http://fd.uf/56hfg#
eius modi tempora incidunt ut labore et
http://fd.uf/56hfg#quo nulla.</span></li>
</ul>
</div>
<div class="clearfix"> </div>
<div class="agile_footer_grids">
<div class="col-md-3 w3_footer_grid agile_footer_grids_w3_footer">
<div class="w3_footer_grid_bottom">
<h4>100% secure payments</h4>
<img src="images/card.png" alt=" " class="img-responsive" />
</div>
</div>
<div class="col-md-3 w3_footer_grid agile_footer_grids_w3_footer">
<div class="w3_footer_grid_bottom">
<h5>connect with us</h5>
<ul class="agileits_social_icons">
<li><i class="fa fa-facebook" aria-hidden="true"></i></li>
<li><i class="fa fa-twitter" aria-hidden="true"></i></li>
<li><i class="fa fa-google-plus" aria-hidden="true"></i></li>
<li><i class="fa fa-instagram" aria-hidden="true"></i></li>
<li><i class="fa fa-dribbble" aria-hidden="true"></i></li>
</ul>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="wthree_footer_copy">
<p>© 2016 Grocery Store. All rights reserved | Design by W3layouts</p>
</div>
</div>
</div>
<!-- //footer -->
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$(".dropdown").hover(
function() {
$('.dropdown-menu', this).stop( true, true ).slideDown("fast");
$(this).toggleClass('open');
},
function() {
$('.dropdown-menu', this).stop( true, true ).slideUp("fast");
$(this).toggleClass('open');
}
);
});
</script>
<!-- here stars scrolling icon -->
<script type="text/javascript">
$(document).ready(function() {
/*
var defaults = {
containerID: 'toTop', // fading element id
containerHoverID: 'toTopHover', // fading element hover id
scrollSpeed: 1200,
easingType: 'linear'
};
*/
$().UItoTop({ easingType: 'easeOutQuart' });
});
</script>
<!-- //here ends scrolling icon -->
<script src="js/minicart.js"></script>
<script>
paypal.minicart.render();
paypal.minicart.cart.on('checkout', function (evt) {
var items = this.items(),
len = items.length,
total = 0,
i;
// Count the number of each item in the cart
for (i = 0; i < len; i++) {
total += items[i].get('quantity');
}
if (total < 3) {
alert('The minimum order quantity is 3. Please add more to your shopping cart before checking out');
evt.preventDefault();
}
});
</script>
</body>
</html>
Images hosting:
link html page view (correct)
https://ibb.co/frTcaw
ling ftl page view (wrong)
https://ibb.co/fLUpoG
project structure:
-web app
-css
-js
-fonts
-images
-WEB-INF
-view
-ftl
index.ftl
Paths to css, fonts and js in ftl page is true.
How can I make a correct view?

Locating elements in <li> using selenium webdriver with java

I need to locate each item and click on it.
I tired this:
List<WebElement> allTournaments = driver.findElements(By.xpath("//*[#id='main-section']/div/div/section/div[1]/ul/li/div/div[1]/div"));
for (WebElement tournament : allTournaments) {
tournament.click();
}
But got the error "element not visible"
The xpath of first element is //[#id='main-section']/div/div/section/div1/ul/li1/div/div1/div
xpath of second element is //[#id='main-section']/div/div/section/div1/ul/li[2]/div/div1/div
like wise..
can anybody help..?
HTML:
<div class="header-toggle-area">
<div class="header-notification-area text-right ng-scope" ng-controller="notificationController">
</header>
<!--HEADER ENDS-->
<div class="content-wrap" style="padding-top: 60px;">
<aside id="main-sidebar">
<!--MAIN SIDEBAR ENDS-->
<main id="main-section">
<div class="main-content">
<div class="ng-scope" ng-controller="NewTournamentsController as tournaments">
<header class="member-title dt-title-main">
<section class="dashboard-tournaments-listing">
<div class="" ng-show="tournaments.Page==1">
<ul class="row dashboard-listing">
<!-- ngRepeat: running in tournaments.runningTournaments -->
<li class="dashboard-listing-items ng-scope" ng-repeat="running in tournaments.runningTournaments" style="">
<div class="dtslider-block">
<div class="dtslider-content">
<img ng-src="../../category/categoryDefault.jpg" alt="slider" src="../../category/categoryDefault.jpg"/>
<div class="hover-contents">
<div class="hc-timer">
<p> Tournament ends in </p>
<div class="hct-ticker ng-binding"> 04:30 - 26/11/16 </div>
</div>
<div class="hc-details">
<div class="hcd-block ng-hide" ng-show="running.JoinedPlayers>0">
<ul class="hc-icons">
</div>
</div>
</div>
Check if each element is visible and clickable as follows:
for (WebElement tournament : allTournaments) {
if (tournament.isDisplayed()
&& ExpectedConditions.elementToBeClickable(tournament).equals(true)) {
tournament.click();
}
}

description The request sent by the client was syntactically incorrect

I am using Spring MVC, Jquery,Hibernate and tomcat while I am trying to call the save method on controller through ajax and Jquery. while click the save button I am getting this syntactically incorrect error on tomcat here is the code
<script type="text/javascript">
function invokeCancel() {
var a = confirm("are you sure to cancel the page");
if (a == true) {
var urlString = "display.do";
$.ajax({
type : "GET",
url : urlString,
success : function(response) {
$("#addEditViewcontractDetailsDiv").html("");
$("#addEditViewcontractDetailsDiv").hide();
},
error : function() {
alert("Error occured during cancel process");
}
});
} else
return false;
}
$("#piId").focusout(function() {
valaidateElement('piId', 'c1');
});
$("#piName").focusout(function() {
validateElement('piName', 'c2');
});
$("#studyId").focusout(function() {
validateElement('studyId', 'c3');
});
$("#studyName").focusout(function() {
validateElement('studyName', 'c4');
});
$("#contractType").focusout(function() {
validateElement('contractType', 'c5');
});
$("#contractStartDate").focusout(function() {
validateElement('contractStartDate', 'c6');
});
$("#contractEndDate").focusout(function() {
validateElement('contractEndDate', 'c7');
});
$("#paymentTerms").focusout(function() {
validateElement('paymentTerms', 'c8');
});
$("#modeOfPayment").focusout(function() {
validateElement('modeOfPayment', 'c9');
});
$("#panNumber").focusout(function() {
validateElement('panNumber', 'c10');
});
function validateAllElements() {
return valaidateElement('piId', 'c1')
&& validateElement('piName', 'c2')
&& validateElement('studyId', 'c3')
&& validateElement('studyName', 'c4')
&& validateElement('contractType', 'c5')
&& validateElement('contractStartDate', 'c6')
&& validateElement('contractEndDate', 'c7')
&& validateElement('paymentTerms', 'c8')
&& validateElement('modeOfPayment', 'c9')
&& validateElement('panNumber', 'c10');
}
$(document).ready(function() {
for ( var i=1; i<11; i++) {
$("#c" + i).hide();
};
$("#saveBtn").click(function() {
if (validateAllElements()) {
$("#contacrtDetailsPage").submit();
}
});
});
$("#updateBtn").click(function() {
if (validateAllElements()) {
$("#contacrtDetailsPage").attr("action", "updateContract.do");
$("#contacrtDetailsPage").submit();
}
});
$(document)
.ready(
function() {
$("#removeVariable").hide();
var counter = 2;
$("#addVariable")
.click(
function() {
$("#removeVariable").show();
if (counter > 10) {
alert("Only 10 milestones allow");
return false;
}
var newTextBoxDiv = $(
document
.createElement('div'))
.attr(
"id",
'milestoneDiv'
+ counter);
newTextBoxDiv
.after()
.html(
'<div class="row">'
+ '<div class="col-md-12">'
+ '<p class="bx-form"><label> MileStone '
+ counter
+ ' </label>'
+ ' '
+ '<input type="text" size="32" id="mileStone" placeholder="Please Enter Milestone" name="mileStone' + counter +
'" path="mileStone' + counter + '" value="" ></p></div></div>');
newTextBoxDiv
.appendTo("#mileStoneGroup");
counter++;
});
$("#removeVariable").click(function() {
counter--;
$("#milestoneDiv" + counter).remove();
if (counter == 2) {
$("#removeVariable").hide();
alert("No more milestones to remove");
return false;
}
});
});
</script>
</head>
<body>
<sf:form id="contacrtDetailsPage" page="contacrtDetailsPage"
modelAttribute="contractDetails" method="post"
action="saveContract.do">
<div class="mx-main">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Contract Details >>
<c:choose>
<c:when test='${ACTION_TYPE == "EDIT"}'>
Update
</c:when>
<c:otherwise>
Create
</c:otherwise>
</c:choose>
</h3>
</div>
<div class="panel-body">
<sf:hidden path="contractDetailsId" />
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="piId">Pi Id <font
color="red">*</font></label>
<sf:input path="piId"
placeholder="Please enter Pi Id" type="text"
id="piId" cols="34" rows="4" maxlength="60"/>
<span id="c1" class="label label-warning">This information is required.</span>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="piName">PI Name <font color="red">*</font></label>
<sf:input path="piName" placeholder="Please Enter PI Name"
type="text" id="piName" size="60" maxlength="60" />
<span id="c2" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="studyId">Study Id <font color="red">*</font></label>
<sf:input path="studyId" placeholder="Please Enter Study Id"
type="text" id="studyId" size="60" maxlength="60" />
<span id="c3" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="studyName">Study Name <font color="red">*</font></label>
<sf:input path="studyName" placeholder="Please Enter Study Name"
type="text" id="studyName" size="60" maxlength="100" />
<span id="c4" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="contractType">Contract Type <font
color="red">*</font></label>
<sf:select path="contractType" id="contractType">
<sf:option value="">-- Select Contract Type --</sf:option>
<sf:option value="Actual">Actual</sf:option>
<sf:option value="Additional">Additional</sf:option>
<sf:option value="Lab">Lab</sf:option>
<sf:option value="Extension">Extension</sf:option>
</sf:select>
<span id="c5" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row" id="otherType">
<div class="col-md-12">
<p class="bx-form">
<label for="contractStartDate">Contract Start Date
<font color="red">*</font>
</label>
<sf:input type="date" path="contractStartDate"
placeholder="Please Enter Contract Start Date"
id="contractStartDate" size="60" />
<span id="c6" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row" id="otherType">
<div class="col-md-12">
<p class="bx-form">
<label for="contractEndDate">Contract End Date <font
color="red">*</font></label>
<sf:input path="contractEndDate"
placeholder="Please Enter Contract End Date" type="date"
id="contractEndDate" size="60" />
<span id="c7" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="paymentTerms">Payment Terms <font
color="red">*</font></label>
<sf:select path="paymentTerms" id="paymentTerms">
<sf:option value="">-- Select Payment Terms --</sf:option>
<sf:option value="One Term">One Term</sf:option>
<sf:option value="MileStone">MileStone</sf:option>
</sf:select>
<span id="c8" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row" id="mileStoneGroup">
<div class="col-md-12" id="milestoneDiv">
<p class="bx-form">
<label for="mileStone1">MileStone </label>
<sf:input path="mileStone" placeholder="Please Enter MileStone1"
type='textbox' id="mileStone1" size="60" maxlength="11" />
<button type="button" id="addVariable" name="addVariable">
<img src="../images/save2.jpg" />
</button>
<button type="button" id="removeVariable" name="removeVariable">
<img src="../images/minus.png" />
</button>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="contractOthers">Others</label>
<sf:input path="contractOthers"
placeholder="Please Enter Others" type="text"
id="contractOthers" size="60" maxlength="60" />
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="irbPayment">IRB Payment</label>
<sf:input path="irbPayment" id="irbPayment"
placeholder="Please Enter IRB Payment" type="text" size="60"
maxlength="60" />
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="iecPayment">IEC Payment</label>
<sf:input path="iecPayment" id="iecPayment"
placeholder="Please Enter IEC Payment" type="text" size="60"
maxlength="60" />
</p>
</div>
</div>
<div class="row" id="otherType">
<div class="col-md-12">
<p class="bx-form">
<label for="modeOfPayment">Mode of Payment <font
color="red">*</font></label>
<sf:select path="modeOfPayment" id="modeOfPayment">
<sf:option value="">-- Select Mode of Payment--</sf:option>
<sf:option value="Cheque">Cheque</sf:option>
<sf:option value="Draft">Draft</sf:option>
<sf:option value="Cash">Cash</sf:option>
</sf:select>
<span id="c9" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="inFavorOf">In Favor Of</label>
<sf:input path="inFavorOf"
placeholder="Please Enter In Favor Of" type="text"
id="inFavorOf" size="60" maxlength="60" />
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="paybleAt">Payable At</label>
<sf:input path="paybleAt" id="paybleAt"
placeHolder="Please Enter The Payable At" size="60"
maxlength="60" />
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<label for="panNumber">PAN Number <font color="red">*</font></label>
<sf:input path="panNumber" id="panNumber"
placeHolder="Please Enter The PAN Number" size="60"
maxlength="30" />
<span id="c10" class="label label-warning">This
information is required.</span>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="bx-form">
<c:choose>
<c:when test='${ACTION_TYPE == "EDIT"}'>
<button type="button" id="updateBtn" class="btn btn-success">Update</button>
</c:when>
<c:otherwise>
<button type="button" id="saveBtn" name="cmd"
class="btn btn-success">Save</button>
</c:otherwise>
</c:choose>
<button type="button" id="cancelBtn" class="btn btn-warning"
onclick="javascript:invokeCancel();">Cancel</button>
</p>
</div>
</div>
</div>
</div>
</div>
</sf:form>
</body>
</html>
Controller:Code
/************************************* Save ContractDetails *****************************/
#RequestMapping(value = "/saveContract", method=RequestMethod.POST)
public ModelAndView saveContractDetails(ContractDetails contractDetails,
BindingResult result) {
contractDetailsService.createContractDetails(contractDetails);
ModelAndView model = new ModelAndView(PagesI.CONTRACT_DETAILS_DISPLAY);
model.addObject("contractDetailsList",
contractDetailsService.getContractDetailsList());
model.addObject("DISPLAY_VIEW_PAGE", "Y");
return model;
}
It seems like your are missing something in your saveContractDetails method inside your controller.
When you submit your form, you are sending a request on "/saveContract" and passing the model attribute contractDetails to it.
In order for Spring to be able to process your request, I think you have to specify inside the declaration of the saveContractDetails method that you are sending a model attribute.
I would try something like that:
#RequestMapping(value = "/saveContract", method=RequestMethod.POST)
public ModelAndView saveContractDetails(#ModelAttribute ContractDetails contractDetails,
BindingResult result) { ... }

Categories