The hotel industry is one of the most important components of the wider service industry, catering for customers who require overnight accommodation. It is closely associated with the travel industry and the hospitality industry. By most definitions, the hotel industry refers not only to hotels, but also to many other forms of overnight accommodation, including hostels, motels, inns and guest houses.
These software components cover functions across Booking, Central Reservation System, Dynamic Pricing, Food & Beverage, Housekeeping, Loyalty Program, Travel Agency areas.
Popular New Releases in Hotels
aws-sam-cli
Release 1.46.0 - Custom/Provided Runtime Support for sam init
stylelint-plugin-stylus
v0.13.0
react-reserver
v1.4.0
bento.editor
Nuget fix
ad-autofanspeed
Speeds fixed from change in HA, now low is low :)
Popular Libraries in Hotels
by aws python
5938 Apache-2.0
CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
by shouryaj98 java
48 MIT
It is a Hotel Management tool which can be used to manage activites like storing customer details, booking rooms of four different types, ordering food for particular rooms, unbooking rooms and showing the bill.
by microsoft javascript
44 MIT
MCW Intelligent analytics
by vigetlabs ruby
38
Double vs Single Quoted Ruby Strings... Which will emerge victorious??
by karolzak python
33 MIT
This POC is using CNTK 2.1 to train model for multiclass classification of images. Our model is able to recognize specific objects (i.e. toilet, tap, sink, bed, lamp, pillow) connected with picture types we are looking for. It plays a big role in a process which will be used to classify pictures from different hotels and determine whether it's a picture of bathroom, bedroom, hotel front, swimming pool, bar, etc.
by mdobydullah php
27
Laravel & Vue CRUD Single Page Application (SPA) Tutorial. Tested on Laravel 5.8
by agriya php
27
Burrow is an online booking platform / software for Real estate marketplace (Realty marketplace), Rental booking, Room sharing, Hotel booking, Office/Parking Space sharing, Car sharing, Bike sharing, Boat sharing, and other Airbnb clones like finder, etc
by siili-auto javascript
25 Apache-2.0
Customizable Room Booking Application for your organization
by ota-meshi javascript
22 MIT
stylelint plugin for Stylus
Trending New libraries in Hotels
by ota-meshi javascript
22 MIT
stylelint plugin for Stylus
by lukas2511 javascript
21 NOASSERTION
Conference website for FrOSCon 2020 (Cloud Edition)
by shmuelpro javascript
16
A grid component allowing to block out time slots. Built to visualize reservations in a hotel management system.
by prashantk0001 javascript
14 Apache-2.0
Highly opinionated Redux state container implementaion for Lightning Web Components (LWC)
by KOBENDigital javascript
14 MIT
Bento Editor is an advanced content editor for Umbraco.
by UbhiTS python
9 Apache-2.0
Automatically control a room fan's speed based on a temperature sensor. Please :star: if you like this app :)
by mariotacke javascript
9 MIT
Advent of Code 2020 Submissions
by aracpyon javascript
8
Final project -- airbnb clone
by icns-distributed-cloud python
8
room number recognition service for indoor self-driving cars
Top Authors in Hotels
1
2 Libraries
24
2
1 Libraries
11
3
1 Libraries
5
4
1 Libraries
7
5
1 Libraries
13
6
1 Libraries
9
7
1 Libraries
33
8
1 Libraries
11
9
1 Libraries
14
10
1 Libraries
27
1
2 Libraries
24
2
1 Libraries
11
3
1 Libraries
5
4
1 Libraries
7
5
1 Libraries
13
6
1 Libraries
9
7
1 Libraries
33
8
1 Libraries
11
9
1 Libraries
14
10
1 Libraries
27
Trending Kits in Hotels
No Trending Kits are available at this moment for Hotels
Trending Discussions on Hotels
I'm trying to get data from api and render it to the screen but I can render only last data not all api response
SQL Check if a date exists between certain 2 dates
How do I Group and List data according to date using Flutter, Firebase - Firestore Database?
Extracting important entities from unstructured data
How to invert range in timepicker?
How are complex fields in Azure Search represented in a database?
Element is not getting selected in Selenium Pytohn Firefox Web Scrapping
Python Selenium iterate table of links clicking each link
I am trying to fetch data from api and show in list or card view
Execute two functions with one button click
QUESTION
I'm trying to get data from api and render it to the screen but I can render only last data not all api response
Asked 2022-Mar-16 at 21:07App.tsx
1export interface Hotel {
2 id: string;
3 name: string;
4 address1: string;
5 address2: string;
6 starRating: number;
7 images: string[];
8 longDescription: string;
9}
10
11export interface Room {
12 id: string;
13 name: string;
14 longDescription: string;
15}
16
17const App: React.FC = () => {
18 const [hotels, setHotels] = useState<Hotel[]>([]);
19 const [rooms, setRooms] = useState<Room[]>([]);
20
21 useEffect(() => {
22 const getDetails = async () => {
23 const hotel = await axios.get<Hotel[]>(`${uri}`);
24 console.log(hotel.data);
25
26 const response = hotel.data.map(async (i) => {
27 const data = await (await fetch(`${uri}/${i.id}`)).json();
28 return data;
29 });
30 Promise.all(response).then((fetchedData) => {
31 const roomData = fetchedData.map((i) => {
32 return i.rooms;
33 });
34 console.log(roomData);
35 setRooms(roomData);
36 });
37 };
38 getDetails();
39 }, []);
40
41 return (
42 <div>
43 <GlobalStyle />
44 <HotelCard hotels={hotels} rooms={rooms} />-
45 </div>
46 );
47};
48
HotelCard.TSX is for only rendering hotel cards with rooms.
1export interface Hotel {
2 id: string;
3 name: string;
4 address1: string;
5 address2: string;
6 starRating: number;
7 images: string[];
8 longDescription: string;
9}
10
11export interface Room {
12 id: string;
13 name: string;
14 longDescription: string;
15}
16
17const App: React.FC = () => {
18 const [hotels, setHotels] = useState<Hotel[]>([]);
19 const [rooms, setRooms] = useState<Room[]>([]);
20
21 useEffect(() => {
22 const getDetails = async () => {
23 const hotel = await axios.get<Hotel[]>(`${uri}`);
24 console.log(hotel.data);
25
26 const response = hotel.data.map(async (i) => {
27 const data = await (await fetch(`${uri}/${i.id}`)).json();
28 return data;
29 });
30 Promise.all(response).then((fetchedData) => {
31 const roomData = fetchedData.map((i) => {
32 return i.rooms;
33 });
34 console.log(roomData);
35 setRooms(roomData);
36 });
37 };
38 getDetails();
39 }, []);
40
41 return (
42 <div>
43 <GlobalStyle />
44 <HotelCard hotels={hotels} rooms={rooms} />-
45 </div>
46 );
47};
48interface HotelListProps {
49 hotels: Hotel[];
50 rooms: Room[];
51}
52
53const HotelCard: React.FC<HotelListProps> = ({ hotels, rooms }) => {
54 return (
55 <div>
56 {hotels.map((hotel) => (
57 <div key={hotel.id}>
58 <h1>{hotel.id}</h1>
59 // more code
60 </div>
61 ))}
62 {rooms.map((room) => (
63 <div key={room.id}>
64 <h1>{room.name}</h1>
65 // more here...
66 </div>
67 ))}
68 </div>
69 );
70};
71
72export default HotelCard;
73
console.log(roomData)
result is
(4) [Array(8), Array(6), Array(9), Array(11)] 0: (8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] 1: (6) [{…}, {…}, {…}, {…}, {…}, {…}] 2: (9) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] 3: (11) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] length: 4 [[Prototype]]: Array(0)
and when I tried to render rooms state and I got only last result not full.
ANSWER
Answered 2022-Mar-15 at 23:20According to your log, roomData is an array of arrays. You can modify your code snippet in Promise.all(...) to have roomData as array of objects:
1export interface Hotel {
2 id: string;
3 name: string;
4 address1: string;
5 address2: string;
6 starRating: number;
7 images: string[];
8 longDescription: string;
9}
10
11export interface Room {
12 id: string;
13 name: string;
14 longDescription: string;
15}
16
17const App: React.FC = () => {
18 const [hotels, setHotels] = useState<Hotel[]>([]);
19 const [rooms, setRooms] = useState<Room[]>([]);
20
21 useEffect(() => {
22 const getDetails = async () => {
23 const hotel = await axios.get<Hotel[]>(`${uri}`);
24 console.log(hotel.data);
25
26 const response = hotel.data.map(async (i) => {
27 const data = await (await fetch(`${uri}/${i.id}`)).json();
28 return data;
29 });
30 Promise.all(response).then((fetchedData) => {
31 const roomData = fetchedData.map((i) => {
32 return i.rooms;
33 });
34 console.log(roomData);
35 setRooms(roomData);
36 });
37 };
38 getDetails();
39 }, []);
40
41 return (
42 <div>
43 <GlobalStyle />
44 <HotelCard hotels={hotels} rooms={rooms} />-
45 </div>
46 );
47};
48interface HotelListProps {
49 hotels: Hotel[];
50 rooms: Room[];
51}
52
53const HotelCard: React.FC<HotelListProps> = ({ hotels, rooms }) => {
54 return (
55 <div>
56 {hotels.map((hotel) => (
57 <div key={hotel.id}>
58 <h1>{hotel.id}</h1>
59 // more code
60 </div>
61 ))}
62 {rooms.map((room) => (
63 <div key={room.id}>
64 <h1>{room.name}</h1>
65 // more here...
66 </div>
67 ))}
68 </div>
69 );
70};
71
72export default HotelCard;
73let roomData = [];
74fetchedData.forEach((i) => {
75 roomData = [...roomData, ...i.rooms];
76});
77
QUESTION
SQL Check if a date exists between certain 2 dates
Asked 2022-Mar-14 at 16:18I have these tables
- Hotel (hotelNo, hotelName, city)
- Room (roomNo, hotelNo, type, price)
- Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)
- Guest(guestNo, guestName, guestAddress)
How can I list hotels and rooms that were not reserved on "1-Mar-2022"?
What I've tried so far:
1SELECT *
2FROM Hotel h, Room r, Booking b
3WHERE h.hotelNo = r.hotelNo
4 AND b.roomNo = r.roomNo
5 ??? AND NOT (b.dateFrom and b.dateTo not contains ‘2022-03-01’) ???
6
ANSWER
Answered 2022-Mar-14 at 13:231SELECT *
2FROM Hotel h, Room r, Booking b
3WHERE h.hotelNo = r.hotelNo
4 AND b.roomNo = r.roomNo
5 ??? AND NOT (b.dateFrom and b.dateTo not contains ‘2022-03-01’) ???
6SELECT * FROM Hotel h,
7JOIN Room r ON h.HotelNo=r.HotelNo
8JOIN Booking b ON b.roomNo = r.roomNo
9 WHERE '2022-03-01' NOT BETWEEN b.dateFrom and b.dateTo
10
QUESTION
How do I Group and List data according to date using Flutter, Firebase - Firestore Database?
Asked 2022-Mar-13 at 10:41I need to have a list of hotels grouped by the dates available (group by - the date they have been added). Please let me know what can be done. The following is my code. Thanks in advance.
1 StreamBuilder(
2 stream: FirebaseFirestore.instance
3 .collection('hotels')
4 .snapshots(),
5 builder:
6 (context, AsyncSnapshot<QuerySnapshot> snapshot) {
7 if (!snapshot.hasData) {
8 return Center(child: CircularProgressIndicator());
9 }
10 return ListView.builder(
11
12
13 itemCount: snapshot.data?.docs.length,
14 itemBuilder: (context, index) {
15 return Stack(
16 children: [
17
I want to have the date specified above each grouped list
1 StreamBuilder(
2 stream: FirebaseFirestore.instance
3 .collection('hotels')
4 .snapshots(),
5 builder:
6 (context, AsyncSnapshot<QuerySnapshot> snapshot) {
7 if (!snapshot.hasData) {
8 return Center(child: CircularProgressIndicator());
9 }
10 return ListView.builder(
11
12
13 itemCount: snapshot.data?.docs.length,
14 itemBuilder: (context, index) {
15 return Stack(
16 children: [
17//the date captured from the group by condition
18 Text("${example date}", style: TextStyle(
19 color: Colors.white
20 ),),
21 Container(
22
23 child: Column(
24
25 children: [
26 Column(
27 crossAxisAlignment:
28 CrossAxisAlignment.end,
29 children: [
30 Padding(
31 padding: const EdgeInsets.only(
32 right: 10.0),
33 child: Text(
34 "${snapshot.data!.docs[index]['name']
35 .toString()}",
36 style: TextStyle(
37 fontSize: 14,
38 color: Colors.white,
39 ),
40 ),
41 ),
42
43
44 ],
45 ),
46
47 ], ), ), ],);}); }, ),
48
49
50
ANSWER
Answered 2022-Mar-13 at 10:41This has already been answered here: Flutter/Dart how to groupBy list of maps
The package collection implements the groupBy function.
QUESTION
Extracting important entities from unstructured data
Asked 2022-Mar-06 at 05:58I am working on a NLP problem where I am completely stuck at certain point. I am new to these so pardon if the question is dumb.
I have got a completely unstructured text let's say: "a person named x y is travelling to country ab, he spent xyz (alpha/currency/beta/gamma), ate a b c d e f food items and many more.
"
now I have to extract
1|name of person| country's name | amount spent and the currency | food items he ate | place of
2stay|
3
Constraint on this is, the text contains some false information, for example: the food b and c cannot be found in a particular country, and thus it should not be extracted. I have a nested dictionary which looks like this:
1|name of person| country's name | amount spent and the currency | food items he ate | place of
2stay|
3{country_name: {place 1: {name of hotels:[hotel1, hotel2, hotel3....],
4 eatables: [food1, food2, food3, food4.....],
5 currency_accepted: [c1, c2, c3, c4.......],
6 }
7 }
8}
9
I want to use this dictionary in the unstructured text so that I can parse the data and extract entities which are relevant in separate columns of dataframe. I have seen NER based approaches, but I guess it requires tagging of words, and I have got huge data.
I have tried regex based approach for pattern matching, but that doesn't give all the results, further to that I have tried to match all the entities stored in a list, but this creates the problem of many false entities being extracted and accuracy is quite important here.
I am looking for more improve parsing based approaches, also if there is any way a certain model is trained on this dictionary such that it looks for values of nested dictionary only if a key is found in the unstructured text.
ANSWER
Answered 2022-Mar-06 at 05:58Before you go to machine learning, you could try using fuzzywuzzy. I had a similar problem at work and was able to achieve high accuracy by adjusting the ratio attribute. So, for each extracted entity, you would have to run it through fuzzywuzzy and your dictionary.
For the issue of
but this creates the problem of many false entities being extracted
I would implement a filter: if the extracted & matched entity is not in the list, leave the extracted entity out, otherwise, continue with the logic.
QUESTION
How to invert range in timepicker?
Asked 2022-Mar-04 at 01:10I started use this https://timepicker.co/ for my small booking project for hotels. but for hotels who open in evening and close on morning I need inverted time range like this :
hotels work from 20 to 08 we don't want to display past hours
so we need display hours like this :
start -> 20,21,22,23,00,01,02,03,04,05,06,07 end -> 21,22,23,00,01,02,03,04,05,06,07,08
now my picker looks like this and work good if range not inverted
1 var initHour = new Date().getHours();
2 if (20 > new Date().getHours()) {
3 initHour = 20;
4 }
5 var intiMinutes = 0;
6
7 var minDateTime = new Date(new Date().setHours(20,0, 0, 0));
8 var maxDateTime = new Date(new Date().setHours(8, 0, 0, 0));
9
10 if (minDateTime < new Date()) {
11 minDateTime = new Date(new Date().setHours(initHour, intiMinutes, 0));
12 }
13
14 $('#TimePickerStart').timepicker({
15 timeFormat: 'HH:mm',
16 dynamic: false,
17 minTime: minDateTime,
18 maxTime: maxDateTime,
19 startTime: new Date(new Date().setHours(initHour, intiMinutes, 0)),
20 startHour: initHour,
21 startMinutes: intiMinutes,
22 interval: 30
23 });
24 $('#TimePickerStart').timepicker('setTime', new Date(new Date().setHours(initHour, intiMinutes, 0, 0)));
25
26 if (intiMinutes >= 30) {
27 initHour = initHour + 1;
28 intiMinutes = 0;
29 }
30 else {
31 intiMinutes = 30;
32 }
33
34 $('#TimePickerEnd').timepicker({
35 timeFormat: 'HH:mm',
36 dynamic: false,
37 minTime: new Date(new Date().setHours(20, 0, 0, 0)),
38 maxTime: maxDateTime,
39 startTime: new Date(0, 0, 0),
40 startHour: initHour,
41 startMinutes: intiMinutes,
42 interval: 30
43 });
44 $('#TimePickerEnd').timepicker('setTime', new Date(new Date().setHours(initHour, intiMinutes, 0, 0)));
1 var initHour = new Date().getHours();
2 if (20 > new Date().getHours()) {
3 initHour = 20;
4 }
5 var intiMinutes = 0;
6
7 var minDateTime = new Date(new Date().setHours(20,0, 0, 0));
8 var maxDateTime = new Date(new Date().setHours(8, 0, 0, 0));
9
10 if (minDateTime < new Date()) {
11 minDateTime = new Date(new Date().setHours(initHour, intiMinutes, 0));
12 }
13
14 $('#TimePickerStart').timepicker({
15 timeFormat: 'HH:mm',
16 dynamic: false,
17 minTime: minDateTime,
18 maxTime: maxDateTime,
19 startTime: new Date(new Date().setHours(initHour, intiMinutes, 0)),
20 startHour: initHour,
21 startMinutes: intiMinutes,
22 interval: 30
23 });
24 $('#TimePickerStart').timepicker('setTime', new Date(new Date().setHours(initHour, intiMinutes, 0, 0)));
25
26 if (intiMinutes >= 30) {
27 initHour = initHour + 1;
28 intiMinutes = 0;
29 }
30 else {
31 intiMinutes = 30;
32 }
33
34 $('#TimePickerEnd').timepicker({
35 timeFormat: 'HH:mm',
36 dynamic: false,
37 minTime: new Date(new Date().setHours(20, 0, 0, 0)),
38 maxTime: maxDateTime,
39 startTime: new Date(0, 0, 0),
40 startHour: initHour,
41 startMinutes: intiMinutes,
42 interval: 30
43 });
44 $('#TimePickerEnd').timepicker('setTime', new Date(new Date().setHours(initHour, intiMinutes, 0, 0)));<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
45
46<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
47
48
49<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
50
51
52<input id="TimePickerStart" style="background-color:white!important" class="form-control" onchange="OnStartHourClick(this)" pattern="[0-9]{2}:[0-9]{2}" required readonly>
53
54
55<input id="TimePickerEnd" style="background-color:white!important" class="form-control" onchange="OnEndHourClick(this)" pattern="[0-9]{2}:[0-9]{2}" required readonly>
ANSWER
Answered 2022-Mar-04 at 01:10This appears to be a existing issue in wvega/timepicker according to this issue timepicker breaks if range crosses meridiem from PM to AM #94
An alternative that seems to meet your criteria is jquery.timepicker
Here's an example of hours spanning overnight, which you should be able to adapt to your additional date logic
1 var initHour = new Date().getHours();
2 if (20 > new Date().getHours()) {
3 initHour = 20;
4 }
5 var intiMinutes = 0;
6
7 var minDateTime = new Date(new Date().setHours(20,0, 0, 0));
8 var maxDateTime = new Date(new Date().setHours(8, 0, 0, 0));
9
10 if (minDateTime < new Date()) {
11 minDateTime = new Date(new Date().setHours(initHour, intiMinutes, 0));
12 }
13
14 $('#TimePickerStart').timepicker({
15 timeFormat: 'HH:mm',
16 dynamic: false,
17 minTime: minDateTime,
18 maxTime: maxDateTime,
19 startTime: new Date(new Date().setHours(initHour, intiMinutes, 0)),
20 startHour: initHour,
21 startMinutes: intiMinutes,
22 interval: 30
23 });
24 $('#TimePickerStart').timepicker('setTime', new Date(new Date().setHours(initHour, intiMinutes, 0, 0)));
25
26 if (intiMinutes >= 30) {
27 initHour = initHour + 1;
28 intiMinutes = 0;
29 }
30 else {
31 intiMinutes = 30;
32 }
33
34 $('#TimePickerEnd').timepicker({
35 timeFormat: 'HH:mm',
36 dynamic: false,
37 minTime: new Date(new Date().setHours(20, 0, 0, 0)),
38 maxTime: maxDateTime,
39 startTime: new Date(0, 0, 0),
40 startHour: initHour,
41 startMinutes: intiMinutes,
42 interval: 30
43 });
44 $('#TimePickerEnd').timepicker('setTime', new Date(new Date().setHours(initHour, intiMinutes, 0, 0)));<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
45
46<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
47
48
49<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
50
51
52<input id="TimePickerStart" style="background-color:white!important" class="form-control" onchange="OnStartHourClick(this)" pattern="[0-9]{2}:[0-9]{2}" required readonly>
53
54
55<input id="TimePickerEnd" style="background-color:white!important" class="form-control" onchange="OnEndHourClick(this)" pattern="[0-9]{2}:[0-9]{2}" required readonly>$('.timepicker').timepicker({
56 minTime: '8:00pm',
57 maxTime: '6:00am',
58 timeFormat: 'H:i'
59});
1 var initHour = new Date().getHours();
2 if (20 > new Date().getHours()) {
3 initHour = 20;
4 }
5 var intiMinutes = 0;
6
7 var minDateTime = new Date(new Date().setHours(20,0, 0, 0));
8 var maxDateTime = new Date(new Date().setHours(8, 0, 0, 0));
9
10 if (minDateTime < new Date()) {
11 minDateTime = new Date(new Date().setHours(initHour, intiMinutes, 0));
12 }
13
14 $('#TimePickerStart').timepicker({
15 timeFormat: 'HH:mm',
16 dynamic: false,
17 minTime: minDateTime,
18 maxTime: maxDateTime,
19 startTime: new Date(new Date().setHours(initHour, intiMinutes, 0)),
20 startHour: initHour,
21 startMinutes: intiMinutes,
22 interval: 30
23 });
24 $('#TimePickerStart').timepicker('setTime', new Date(new Date().setHours(initHour, intiMinutes, 0, 0)));
25
26 if (intiMinutes >= 30) {
27 initHour = initHour + 1;
28 intiMinutes = 0;
29 }
30 else {
31 intiMinutes = 30;
32 }
33
34 $('#TimePickerEnd').timepicker({
35 timeFormat: 'HH:mm',
36 dynamic: false,
37 minTime: new Date(new Date().setHours(20, 0, 0, 0)),
38 maxTime: maxDateTime,
39 startTime: new Date(0, 0, 0),
40 startHour: initHour,
41 startMinutes: intiMinutes,
42 interval: 30
43 });
44 $('#TimePickerEnd').timepicker('setTime', new Date(new Date().setHours(initHour, intiMinutes, 0, 0)));<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
45
46<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
47
48
49<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
50
51
52<input id="TimePickerStart" style="background-color:white!important" class="form-control" onchange="OnStartHourClick(this)" pattern="[0-9]{2}:[0-9]{2}" required readonly>
53
54
55<input id="TimePickerEnd" style="background-color:white!important" class="form-control" onchange="OnEndHourClick(this)" pattern="[0-9]{2}:[0-9]{2}" required readonly>$('.timepicker').timepicker({
56 minTime: '8:00pm',
57 maxTime: '6:00am',
58 timeFormat: 'H:i'
59});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
60<script src="https://cdn.jsdelivr.net/npm/timepicker@1.13.18/jquery.timepicker.js"></script>
61<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/timepicker@1.13.18/jquery.timepicker.css">
62
63<input class="timepicker" >
QUESTION
How are complex fields in Azure Search represented in a database?
Asked 2022-Mar-04 at 00:40When using Azure Cognitive Search, you can push complex fields to the index with JSON, like so (using a simplified version of the official Hotels example):
1{
2 "HotelId": "1",
3 "HotelName": "Secret Point Hotel",
4 "Category": "Boutique",
5 "Tags": [ "view", "air conditioning", "concierge" ],
6 "Address": {
7 "StreetAddress": "677 5th Ave",
8 "City": "New York",
9 "StateProvince": "NY",
10 "PostalCode": "10022",
11 "Country": "USA"
12 },
13 "Rooms": [
14 {
15 "Description": "Budget Room, 1 Queen Bed (Cityside)",
16 "Description_fr": "Chambre Économique, 1 grand lit (côté ville)",
17 "Type": "Budget Room",
18 "BaseRate": 96.99,
19 "BedOptions": "1 Queen Bed",
20 "SleepsCount": 2,
21 "SmokingAllowed": true,
22 "Tags": [ "vcr/dvd" ]
23 },
24 {
25 "Description": "Budget Room, 1 King Bed (Mountain View)",
26 "Description_fr": "Chambre Économique, 1 très grand lit (Mountain View)",
27 "Type": "Budget Room",
28 "BaseRate": 80.99,
29 "BedOptions": "1 King Bed",
30 "SleepsCount": 2,
31 "SmokingAllowed": true,
32 "Tags": [ "vcr/dvd", "jacuzzi tub" ]
33 },
34 ]
35}
36
Notice how there are a couple complex field types here, Tags, Address, and Rooms. Since Rooms is the most difficult of the three, let's model out Rooms. The official SQL scripts do not include any sort of data creation for rooms, so I can't see how an indexer might find/read that data.
How do I need to represent my data (in the view that the indexer is reading from) in order to create a complex collection such as the Rooms
example above?
If that's not possible, is it even possible to represent Address
in the database in a way that it could be transferred to Azure Search in the schema below?
ANSWER
Answered 2022-Mar-04 at 00:40You will need to create a Data Source that is attached to a SQL view that contains all of your Hotel data. Your view should have columns (Tags, Address, Rooms) that contain embedded JSON which represent the complex types.
This is an example of creating a view with a 'Rooms' column that will contain data from the Rooms table:
1{
2 "HotelId": "1",
3 "HotelName": "Secret Point Hotel",
4 "Category": "Boutique",
5 "Tags": [ "view", "air conditioning", "concierge" ],
6 "Address": {
7 "StreetAddress": "677 5th Ave",
8 "City": "New York",
9 "StateProvince": "NY",
10 "PostalCode": "10022",
11 "Country": "USA"
12 },
13 "Rooms": [
14 {
15 "Description": "Budget Room, 1 Queen Bed (Cityside)",
16 "Description_fr": "Chambre Économique, 1 grand lit (côté ville)",
17 "Type": "Budget Room",
18 "BaseRate": 96.99,
19 "BedOptions": "1 Queen Bed",
20 "SleepsCount": 2,
21 "SmokingAllowed": true,
22 "Tags": [ "vcr/dvd" ]
23 },
24 {
25 "Description": "Budget Room, 1 King Bed (Mountain View)",
26 "Description_fr": "Chambre Économique, 1 très grand lit (Mountain View)",
27 "Type": "Budget Room",
28 "BaseRate": 80.99,
29 "BedOptions": "1 King Bed",
30 "SleepsCount": 2,
31 "SmokingAllowed": true,
32 "Tags": [ "vcr/dvd", "jacuzzi tub" ]
33 },
34 ]
35}
36CREATE VIEW [dbo].[HotelRooms]
37AS
38SELECT *, (SELECT *
39 FROM dbo.Rooms
40 WHERE dbo.Rooms.HotelID = dbo.Hotels.HotelID FOR JSON AUTO) AS Rooms
41FROM dbo.Hotels
42GO
43
This view will have a column Room
which will be populated with a JSON array eg: [{"Description": "Budget Room"},{"Description": "Another Room"}]
The columns listed on your view should match exactly with your Index schema. You will need to create a field on your Index called Room
of type Collection(Edm.ComplexType)
which will contain child fields such as Description
.
For more information please see here: https://docs.microsoft.com/en-us/azure/search/index-sql-relational-data
QUESTION
Element is not getting selected in Selenium Pytohn Firefox Web Scrapping
Asked 2022-Feb-27 at 20:18I have problem with element selection checkbox with one of the list item in below code snippet.
I'm able to select 1st 2nd & 4th Element in below code, however I'm not able to select 3rd element.
When i give only Taj Hotels, Oberoi Hotels and Sheraton India. All three are getting checked by python selenium web scrapping. when i add Windsor Hotels to list, it's not selecting it script shows error like below.
selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view
Note: whenever an item is selected it's class name is getting is changed to "list-item star ng-star-inserted active"
I'm running this using windows 10, Pycharm IDE.
selenium==3.7.0 cryptography=3.1.1 pandas
Python Script:
1 txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
2 txt_button.click()
3
1 txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
2 txt_button.click()
3<!DOCTYPE html>
4<html lang="en">
5
6<body>
7<fd-order-supplier-list _ngcontent-ydw-c199="">
8 <div class="block-list block-list-selectable block-list-sm">
9 <div class="the-list">
10 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
11 <div _ngcontent-ydw-c198="" class="list-item-inner">
12 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
13 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">H</div><!----></div>
14 <div _ngcontent-ydw-c198="" class="item-name" style="">Taj Hotels</div>
15 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
16 class="btn btn-outline-default btn-xs">Add</a></div>
17 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
18 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
19 </div>
20 </div><!----><a _ngcontent-ydw-c198=""
21 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
22 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
23 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
24 </div>
25 </fd-order-supplier-list-item>
26 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
27 <div _ngcontent-ydw-c198="" class="list-item-inner">
28 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
29 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">I</div><!----></div>
30 <div _ngcontent-ydw-c198="" class="item-name" style="">Oberoi Hotels</div>
31 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
32 class="btn btn-outline-default btn-xs">Add</a></div>
33 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
34 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
35 </div>
36 </div><!----><a _ngcontent-ydw-c198=""
37 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
38 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
39 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
40 </div>
41 </fd-order-supplier-list-item>
42 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
43 <div _ngcontent-ydw-c198="" class="list-item-inner">
44
45 <div _ngcontent-ydw-c198="" class="item-name">Windsor Hotels</div>
46 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
47 class="btn btn-outline-default btn-xs">Add</a></div>
48 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
49 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
50 </div>
51 </div><!----><a _ngcontent-ydw-c198=""
52 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
53 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
54 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
55 </div>
56 </fd-order-supplier-list-item>
57 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
58 <div _ngcontent-ydw-c198="" class="list-item-inner">
59
60 <div _ngcontent-ydw-c198="" class="item-name">Sheraton India</div>
61 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
62 class="btn btn-outline-default btn-xs">Add</a></div>
63 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
64 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
65 </div>
66 </div><!----><a _ngcontent-ydw-c198=""
67 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
68 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
69 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
70 </div>
71 </fd-order-supplier-list-item>
72 </div>
73</fd-order-supplier-list>
74</body>
75</html>
ANSWER
Answered 2022-Feb-27 at 20:18Instead of:
1 txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
2 txt_button.click()
3<!DOCTYPE html>
4<html lang="en">
5
6<body>
7<fd-order-supplier-list _ngcontent-ydw-c199="">
8 <div class="block-list block-list-selectable block-list-sm">
9 <div class="the-list">
10 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
11 <div _ngcontent-ydw-c198="" class="list-item-inner">
12 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
13 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">H</div><!----></div>
14 <div _ngcontent-ydw-c198="" class="item-name" style="">Taj Hotels</div>
15 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
16 class="btn btn-outline-default btn-xs">Add</a></div>
17 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
18 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
19 </div>
20 </div><!----><a _ngcontent-ydw-c198=""
21 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
22 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
23 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
24 </div>
25 </fd-order-supplier-list-item>
26 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
27 <div _ngcontent-ydw-c198="" class="list-item-inner">
28 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
29 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">I</div><!----></div>
30 <div _ngcontent-ydw-c198="" class="item-name" style="">Oberoi Hotels</div>
31 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
32 class="btn btn-outline-default btn-xs">Add</a></div>
33 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
34 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
35 </div>
36 </div><!----><a _ngcontent-ydw-c198=""
37 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
38 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
39 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
40 </div>
41 </fd-order-supplier-list-item>
42 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
43 <div _ngcontent-ydw-c198="" class="list-item-inner">
44
45 <div _ngcontent-ydw-c198="" class="item-name">Windsor Hotels</div>
46 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
47 class="btn btn-outline-default btn-xs">Add</a></div>
48 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
49 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
50 </div>
51 </div><!----><a _ngcontent-ydw-c198=""
52 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
53 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
54 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
55 </div>
56 </fd-order-supplier-list-item>
57 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
58 <div _ngcontent-ydw-c198="" class="list-item-inner">
59
60 <div _ngcontent-ydw-c198="" class="item-name">Sheraton India</div>
61 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
62 class="btn btn-outline-default btn-xs">Add</a></div>
63 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
64 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
65 </div>
66 </div><!----><a _ngcontent-ydw-c198=""
67 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
68 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
69 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
70 </div>
71 </fd-order-supplier-list-item>
72 </div>
73</fd-order-supplier-list>
74</body>
75</html>txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
76
you can get more canonical adding the tag_name and the class attribute as follows:
1 txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
2 txt_button.click()
3<!DOCTYPE html>
4<html lang="en">
5
6<body>
7<fd-order-supplier-list _ngcontent-ydw-c199="">
8 <div class="block-list block-list-selectable block-list-sm">
9 <div class="the-list">
10 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
11 <div _ngcontent-ydw-c198="" class="list-item-inner">
12 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
13 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">H</div><!----></div>
14 <div _ngcontent-ydw-c198="" class="item-name" style="">Taj Hotels</div>
15 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
16 class="btn btn-outline-default btn-xs">Add</a></div>
17 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
18 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
19 </div>
20 </div><!----><a _ngcontent-ydw-c198=""
21 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
22 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
23 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
24 </div>
25 </fd-order-supplier-list-item>
26 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
27 <div _ngcontent-ydw-c198="" class="list-item-inner">
28 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
29 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">I</div><!----></div>
30 <div _ngcontent-ydw-c198="" class="item-name" style="">Oberoi Hotels</div>
31 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
32 class="btn btn-outline-default btn-xs">Add</a></div>
33 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
34 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
35 </div>
36 </div><!----><a _ngcontent-ydw-c198=""
37 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
38 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
39 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
40 </div>
41 </fd-order-supplier-list-item>
42 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
43 <div _ngcontent-ydw-c198="" class="list-item-inner">
44
45 <div _ngcontent-ydw-c198="" class="item-name">Windsor Hotels</div>
46 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
47 class="btn btn-outline-default btn-xs">Add</a></div>
48 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
49 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
50 </div>
51 </div><!----><a _ngcontent-ydw-c198=""
52 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
53 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
54 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
55 </div>
56 </fd-order-supplier-list-item>
57 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
58 <div _ngcontent-ydw-c198="" class="list-item-inner">
59
60 <div _ngcontent-ydw-c198="" class="item-name">Sheraton India</div>
61 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
62 class="btn btn-outline-default btn-xs">Add</a></div>
63 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
64 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
65 </div>
66 </div><!----><a _ngcontent-ydw-c198=""
67 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
68 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
69 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
70 </div>
71 </fd-order-supplier-list-item>
72 </div>
73</fd-order-supplier-list>
74</body>
75</html>txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
76txt_button = browser.find_element_by_xpath("//div[@class='item-name' and text()='" + element_to_be selected + "']")
77
precisely:
1 txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
2 txt_button.click()
3<!DOCTYPE html>
4<html lang="en">
5
6<body>
7<fd-order-supplier-list _ngcontent-ydw-c199="">
8 <div class="block-list block-list-selectable block-list-sm">
9 <div class="the-list">
10 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
11 <div _ngcontent-ydw-c198="" class="list-item-inner">
12 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
13 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">H</div><!----></div>
14 <div _ngcontent-ydw-c198="" class="item-name" style="">Taj Hotels</div>
15 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
16 class="btn btn-outline-default btn-xs">Add</a></div>
17 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
18 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
19 </div>
20 </div><!----><a _ngcontent-ydw-c198=""
21 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
22 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
23 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
24 </div>
25 </fd-order-supplier-list-item>
26 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
27 <div _ngcontent-ydw-c198="" class="list-item-inner">
28 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
29 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">I</div><!----></div>
30 <div _ngcontent-ydw-c198="" class="item-name" style="">Oberoi Hotels</div>
31 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
32 class="btn btn-outline-default btn-xs">Add</a></div>
33 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
34 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
35 </div>
36 </div><!----><a _ngcontent-ydw-c198=""
37 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
38 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
39 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
40 </div>
41 </fd-order-supplier-list-item>
42 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
43 <div _ngcontent-ydw-c198="" class="list-item-inner">
44
45 <div _ngcontent-ydw-c198="" class="item-name">Windsor Hotels</div>
46 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
47 class="btn btn-outline-default btn-xs">Add</a></div>
48 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
49 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
50 </div>
51 </div><!----><a _ngcontent-ydw-c198=""
52 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
53 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
54 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
55 </div>
56 </fd-order-supplier-list-item>
57 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
58 <div _ngcontent-ydw-c198="" class="list-item-inner">
59
60 <div _ngcontent-ydw-c198="" class="item-name">Sheraton India</div>
61 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
62 class="btn btn-outline-default btn-xs">Add</a></div>
63 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
64 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
65 </div>
66 </div><!----><a _ngcontent-ydw-c198=""
67 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
68 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
69 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
70 </div>
71 </fd-order-supplier-list-item>
72 </div>
73</fd-order-supplier-list>
74</body>
75</html>txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
76txt_button = browser.find_element_by_xpath("//div[@class='item-name' and text()='" + element_to_be selected + "']")
77txt_button = driver.find_element(By.XPATH, "//div[@class='item-name' and text()='" + element_to_be selected + "']")
78
Note : You have to add the following imports :
1 txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
2 txt_button.click()
3<!DOCTYPE html>
4<html lang="en">
5
6<body>
7<fd-order-supplier-list _ngcontent-ydw-c199="">
8 <div class="block-list block-list-selectable block-list-sm">
9 <div class="the-list">
10 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
11 <div _ngcontent-ydw-c198="" class="list-item-inner">
12 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
13 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">H</div><!----></div>
14 <div _ngcontent-ydw-c198="" class="item-name" style="">Taj Hotels</div>
15 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
16 class="btn btn-outline-default btn-xs">Add</a></div>
17 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
18 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
19 </div>
20 </div><!----><a _ngcontent-ydw-c198=""
21 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
22 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
23 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
24 </div>
25 </fd-order-supplier-list-item>
26 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
27 <div _ngcontent-ydw-c198="" class="list-item-inner">
28 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
29 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">I</div><!----></div>
30 <div _ngcontent-ydw-c198="" class="item-name" style="">Oberoi Hotels</div>
31 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
32 class="btn btn-outline-default btn-xs">Add</a></div>
33 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
34 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
35 </div>
36 </div><!----><a _ngcontent-ydw-c198=""
37 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
38 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
39 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
40 </div>
41 </fd-order-supplier-list-item>
42 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
43 <div _ngcontent-ydw-c198="" class="list-item-inner">
44
45 <div _ngcontent-ydw-c198="" class="item-name">Windsor Hotels</div>
46 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
47 class="btn btn-outline-default btn-xs">Add</a></div>
48 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
49 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
50 </div>
51 </div><!----><a _ngcontent-ydw-c198=""
52 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
53 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
54 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
55 </div>
56 </fd-order-supplier-list-item>
57 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
58 <div _ngcontent-ydw-c198="" class="list-item-inner">
59
60 <div _ngcontent-ydw-c198="" class="item-name">Sheraton India</div>
61 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
62 class="btn btn-outline-default btn-xs">Add</a></div>
63 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
64 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
65 </div>
66 </div><!----><a _ngcontent-ydw-c198=""
67 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
68 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
69 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
70 </div>
71 </fd-order-supplier-list-item>
72 </div>
73</fd-order-supplier-list>
74</body>
75</html>txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
76txt_button = browser.find_element_by_xpath("//div[@class='item-name' and text()='" + element_to_be selected + "']")
77txt_button = driver.find_element(By.XPATH, "//div[@class='item-name' and text()='" + element_to_be selected + "']")
78from selenium.webdriver.common.by import By
79
Ideally to invoke click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
1 txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
2 txt_button.click()
3<!DOCTYPE html>
4<html lang="en">
5
6<body>
7<fd-order-supplier-list _ngcontent-ydw-c199="">
8 <div class="block-list block-list-selectable block-list-sm">
9 <div class="the-list">
10 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
11 <div _ngcontent-ydw-c198="" class="list-item-inner">
12 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
13 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">H</div><!----></div>
14 <div _ngcontent-ydw-c198="" class="item-name" style="">Taj Hotels</div>
15 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
16 class="btn btn-outline-default btn-xs">Add</a></div>
17 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
18 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
19 </div>
20 </div><!----><a _ngcontent-ydw-c198=""
21 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
22 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
23 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
24 </div>
25 </fd-order-supplier-list-item>
26 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
27 <div _ngcontent-ydw-c198="" class="list-item-inner">
28 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
29 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">I</div><!----></div>
30 <div _ngcontent-ydw-c198="" class="item-name" style="">Oberoi Hotels</div>
31 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
32 class="btn btn-outline-default btn-xs">Add</a></div>
33 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
34 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
35 </div>
36 </div><!----><a _ngcontent-ydw-c198=""
37 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
38 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
39 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
40 </div>
41 </fd-order-supplier-list-item>
42 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
43 <div _ngcontent-ydw-c198="" class="list-item-inner">
44
45 <div _ngcontent-ydw-c198="" class="item-name">Windsor Hotels</div>
46 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
47 class="btn btn-outline-default btn-xs">Add</a></div>
48 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
49 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
50 </div>
51 </div><!----><a _ngcontent-ydw-c198=""
52 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
53 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
54 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
55 </div>
56 </fd-order-supplier-list-item>
57 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
58 <div _ngcontent-ydw-c198="" class="list-item-inner">
59
60 <div _ngcontent-ydw-c198="" class="item-name">Sheraton India</div>
61 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
62 class="btn btn-outline-default btn-xs">Add</a></div>
63 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
64 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
65 </div>
66 </div><!----><a _ngcontent-ydw-c198=""
67 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
68 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
69 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
70 </div>
71 </fd-order-supplier-list-item>
72 </div>
73</fd-order-supplier-list>
74</body>
75</html>txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
76txt_button = browser.find_element_by_xpath("//div[@class='item-name' and text()='" + element_to_be selected + "']")
77txt_button = driver.find_element(By.XPATH, "//div[@class='item-name' and text()='" + element_to_be selected + "']")
78from selenium.webdriver.common.by import By
79WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='item-name' and text()='" + element_to_be selected + "']"))).click()
80
Note : You have to add the following imports :
1 txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
2 txt_button.click()
3<!DOCTYPE html>
4<html lang="en">
5
6<body>
7<fd-order-supplier-list _ngcontent-ydw-c199="">
8 <div class="block-list block-list-selectable block-list-sm">
9 <div class="the-list">
10 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
11 <div _ngcontent-ydw-c198="" class="list-item-inner">
12 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
13 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">H</div><!----></div>
14 <div _ngcontent-ydw-c198="" class="item-name" style="">Taj Hotels</div>
15 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
16 class="btn btn-outline-default btn-xs">Add</a></div>
17 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
18 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
19 </div>
20 </div><!----><a _ngcontent-ydw-c198=""
21 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
22 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
23 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
24 </div>
25 </fd-order-supplier-list-item>
26 <fd-order-supplier-list-item class="list-item star ng-star-inserted active" _nghost-ydw-c198="">
27 <div _ngcontent-ydw-c198="" class="list-item-inner">
28 <div _ngcontent-ydw-c198="" class="item-logo placeholder"><!---->
29 <div _ngcontent-ydw-c198="" class="logo-placeholder-inner ng-star-inserted">I</div><!----></div>
30 <div _ngcontent-ydw-c198="" class="item-name" style="">Oberoi Hotels</div>
31 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
32 class="btn btn-outline-default btn-xs">Add</a></div>
33 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
34 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
35 </div>
36 </div><!----><a _ngcontent-ydw-c198=""
37 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
38 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
39 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
40 </div>
41 </fd-order-supplier-list-item>
42 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
43 <div _ngcontent-ydw-c198="" class="list-item-inner">
44
45 <div _ngcontent-ydw-c198="" class="item-name">Windsor Hotels</div>
46 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
47 class="btn btn-outline-default btn-xs">Add</a></div>
48 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
49 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
50 </div>
51 </div><!----><a _ngcontent-ydw-c198=""
52 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
53 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
54 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
55 </div>
56 </fd-order-supplier-list-item>
57 <fd-order-supplier-list-item class="list-item star ng-star-inserted" _nghost-ydw-c198="">
58 <div _ngcontent-ydw-c198="" class="list-item-inner">
59
60 <div _ngcontent-ydw-c198="" class="item-name">Sheraton India</div>
61 <div _ngcontent-ydw-c198="" class="item-btn"><a _ngcontent-ydw-c198=""
62 class="btn btn-outline-default btn-xs">Add</a></div>
63 <div _ngcontent-ydw-c198="" class="item-check ng-star-inserted">
64 <div _ngcontent-ydw-c198="" class="item-checkbox"><span _ngcontent-ydw-c198="" class="icon">check</span>
65 </div>
66 </div><!----><a _ngcontent-ydw-c198=""
67 class="btn btn-sm btn-icon btn-text item-info-link ng-star-inserted"><span
68 _ngcontent-ydw-c198="" class="icon">visibility</span></a><!---->
69 <div _ngcontent-ydw-c198="" class="item-upper-text">IN</div>
70 </div>
71 </fd-order-supplier-list-item>
72 </div>
73</fd-order-supplier-list>
74</body>
75</html>txt_button = browser.find_element_by_xpath('//*[text() = "' + element_to_be selected + '"]')
76txt_button = browser.find_element_by_xpath("//div[@class='item-name' and text()='" + element_to_be selected + "']")
77txt_button = driver.find_element(By.XPATH, "//div[@class='item-name' and text()='" + element_to_be selected + "']")
78from selenium.webdriver.common.by import By
79WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='item-name' and text()='" + element_to_be selected + "']"))).click()
80from selenium.webdriver.support.ui import WebDriverWait
81from selenium.webdriver.common.by import By
82from selenium.webdriver.support import expected_conditions as EC
83
QUESTION
Python Selenium iterate table of links clicking each link
Asked 2022-Jan-12 at 17:38So this question has been asked before but I am still struggling to get it working.
The webpage has a table with links, I want to iterate through clicking each of the links.
So this is my code so far
1from selenium import webdriver
2from selenium.webdriver.support.ui import WebDriverWait
3from selenium.webdriver.support import expected_conditions as EC
4
5driver = webdriver.Chrome(executable_path=r'C:\Users\my_path\chromedriver_96.exe')
6driver.get(r"https://www.fidelity.co.uk/shares/ftse-350/")
7
8try:
9 element = WebDriverWait(driver, 20).until(
10 EC.presence_of_element_located((By.CLASS_NAME, "table-scroll")))
11
12 table = element.find_elements_by_xpath("//table//tbody/tr")
13
14 for row in table[1:]:
15 print(row.get_attribute('innerHTML'))
16 # link.click()
17
18finally:
19 driver.close()
20
21
Sample of output
1from selenium import webdriver
2from selenium.webdriver.support.ui import WebDriverWait
3from selenium.webdriver.support import expected_conditions as EC
4
5driver = webdriver.Chrome(executable_path=r'C:\Users\my_path\chromedriver_96.exe')
6driver.get(r"https://www.fidelity.co.uk/shares/ftse-350/")
7
8try:
9 element = WebDriverWait(driver, 20).until(
10 EC.presence_of_element_located((By.CLASS_NAME, "table-scroll")))
11
12 table = element.find_elements_by_xpath("//table//tbody/tr")
13
14 for row in table[1:]:
15 print(row.get_attribute('innerHTML'))
16 # link.click()
17
18finally:
19 driver.close()
20
21 <td>FOUR</td>
22 <td><a href="/factsheets/4IMPRINT-GROUP/GB0006640972-GBP/?id=GB0006640972GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">4imprint Group plc</a></td>
23 <td>Media &amp; Publishing</td>
24
25
26 <td>888</td>
27 <td><a href="/factsheets/888-HOLDINGS/GI000A0F6407-GBP/?id=GI000A0F6407GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">888 Holdings</a></td>
28 <td>Hotels &amp; Entertainment Services</td>
29
30
31 <td>ASL</td>
32 <td><a href="/factsheets/ABERFORTH-SMALLER-COMPANIES-TRUST/GB0000066554-GBP/?id=GB0000066554GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">Aberforth Smaller Companies Trust</a></td>
33 <td>Collective Investments</td>
34
35
36
How do a click the href and iterate to the next href?
Many thanks.
edit I went with this solution (a few small tweaks on Prophet's solution)
1from selenium import webdriver
2from selenium.webdriver.support.ui import WebDriverWait
3from selenium.webdriver.support import expected_conditions as EC
4
5driver = webdriver.Chrome(executable_path=r'C:\Users\my_path\chromedriver_96.exe')
6driver.get(r"https://www.fidelity.co.uk/shares/ftse-350/")
7
8try:
9 element = WebDriverWait(driver, 20).until(
10 EC.presence_of_element_located((By.CLASS_NAME, "table-scroll")))
11
12 table = element.find_elements_by_xpath("//table//tbody/tr")
13
14 for row in table[1:]:
15 print(row.get_attribute('innerHTML'))
16 # link.click()
17
18finally:
19 driver.close()
20
21 <td>FOUR</td>
22 <td><a href="/factsheets/4IMPRINT-GROUP/GB0006640972-GBP/?id=GB0006640972GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">4imprint Group plc</a></td>
23 <td>Media &amp; Publishing</td>
24
25
26 <td>888</td>
27 <td><a href="/factsheets/888-HOLDINGS/GI000A0F6407-GBP/?id=GI000A0F6407GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">888 Holdings</a></td>
28 <td>Hotels &amp; Entertainment Services</td>
29
30
31 <td>ASL</td>
32 <td><a href="/factsheets/ABERFORTH-SMALLER-COMPANIES-TRUST/GB0000066554-GBP/?id=GB0000066554GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">Aberforth Smaller Companies Trust</a></td>
33 <td>Collective Investments</td>
34
35
36from selenium import webdriver
37from selenium.webdriver.support.ui import WebDriverWait
38from selenium.webdriver.common.by import By
39from selenium.webdriver.support import expected_conditions as EC
40import time
41from selenium.webdriver.common.action_chains import ActionChains
42
43
44driver = webdriver.Chrome(executable_path=r'C:\Users\my_path\chromedriver_96.exe')
45driver.get(r"https://www.fidelity.co.uk/shares/ftse-350/")
46actions = ActionChains(driver)
47#close the cookies banner
48WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "ensCloseBanner"))).click()
49#wait for the first link in the table
50WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table//tbody/tr/td/a")))
51#extra wait to make all the links loaded
52time.sleep(1)
53#get the total links amount
54links = driver.find_elements_by_xpath('//table//tbody/tr/td/a')
55
56for index, val in enumerate(links):
57 try:
58 #get the links again after getting back to the initial page in the loop
59 links = driver.find_elements_by_xpath('//table//tbody/tr/td/a')
60 #scroll to the n-th link, it may be out of the initially visible area
61 actions.move_to_element(links[index]).perform()
62 links[index].click()
63 #scrape the data on the new page and get back with the following command
64 driver.execute_script("window.history.go(-1)") #you can alternatevely use this as well: driver.back()
65 WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table//tbody/tr/td/a")))
66 time.sleep(2)
67 except StaleElementReferenceException:
68 pass
69
ANSWER
Answered 2022-Jan-12 at 16:44To perform what you want to do here you first need to close cookies banner on the bottom of the page.
Then you can iterate over the links in the table.
Since by clicking on each link you are opening a new page, after scaring the data there you will have to get back to the main page and get the next link. You can not just get all the links into some list and then iterate over that list since by navigating to another web page all the existing elements grabbed by Selenium on the initial page become Stale.
Your code can be something like this:
1from selenium import webdriver
2from selenium.webdriver.support.ui import WebDriverWait
3from selenium.webdriver.support import expected_conditions as EC
4
5driver = webdriver.Chrome(executable_path=r'C:\Users\my_path\chromedriver_96.exe')
6driver.get(r"https://www.fidelity.co.uk/shares/ftse-350/")
7
8try:
9 element = WebDriverWait(driver, 20).until(
10 EC.presence_of_element_located((By.CLASS_NAME, "table-scroll")))
11
12 table = element.find_elements_by_xpath("//table//tbody/tr")
13
14 for row in table[1:]:
15 print(row.get_attribute('innerHTML'))
16 # link.click()
17
18finally:
19 driver.close()
20
21 <td>FOUR</td>
22 <td><a href="/factsheets/4IMPRINT-GROUP/GB0006640972-GBP/?id=GB0006640972GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">4imprint Group plc</a></td>
23 <td>Media &amp; Publishing</td>
24
25
26 <td>888</td>
27 <td><a href="/factsheets/888-HOLDINGS/GI000A0F6407-GBP/?id=GI000A0F6407GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">888 Holdings</a></td>
28 <td>Hotels &amp; Entertainment Services</td>
29
30
31 <td>ASL</td>
32 <td><a href="/factsheets/ABERFORTH-SMALLER-COMPANIES-TRUST/GB0000066554-GBP/?id=GB0000066554GBP&amp;idType=isin&amp;marketCode=&amp;idCurrencyid=" target="_parent">Aberforth Smaller Companies Trust</a></td>
33 <td>Collective Investments</td>
34
35
36from selenium import webdriver
37from selenium.webdriver.support.ui import WebDriverWait
38from selenium.webdriver.common.by import By
39from selenium.webdriver.support import expected_conditions as EC
40import time
41from selenium.webdriver.common.action_chains import ActionChains
42
43
44driver = webdriver.Chrome(executable_path=r'C:\Users\my_path\chromedriver_96.exe')
45driver.get(r"https://www.fidelity.co.uk/shares/ftse-350/")
46actions = ActionChains(driver)
47#close the cookies banner
48WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "ensCloseBanner"))).click()
49#wait for the first link in the table
50WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table//tbody/tr/td/a")))
51#extra wait to make all the links loaded
52time.sleep(1)
53#get the total links amount
54links = driver.find_elements_by_xpath('//table//tbody/tr/td/a')
55
56for index, val in enumerate(links):
57 try:
58 #get the links again after getting back to the initial page in the loop
59 links = driver.find_elements_by_xpath('//table//tbody/tr/td/a')
60 #scroll to the n-th link, it may be out of the initially visible area
61 actions.move_to_element(links[index]).perform()
62 links[index].click()
63 #scrape the data on the new page and get back with the following command
64 driver.execute_script("window.history.go(-1)") #you can alternatevely use this as well: driver.back()
65 WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table//tbody/tr/td/a")))
66 time.sleep(2)
67 except StaleElementReferenceException:
68 pass
69from selenium import webdriver
70from selenium.webdriver.support.ui import WebDriverWait
71from selenium.webdriver.common.by import By
72from selenium.webdriver.support import expected_conditions as EC
73import time
74
75
76driver = webdriver.Chrome(executable_path=r'C:\Users\my_path\chromedriver_96.exe')
77driver.get(r"https://www.fidelity.co.uk/shares/ftse-350/")
78actions = ActionChains(driver)
79#close the cookies banner
80WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "ensCloseBanner"))).click()
81#wait for the first link in the table
82WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table//tbody/tr/td/a")))
83#extra wait to make all the links loaded
84time.sleep(1)
85#get the total links amount
86links = driver.find_elements_by_xpath('//table//tbody/tr/td/a')
87for index, val in enumerate(links):
88 #get the links again after getting back to the initial page in the loop
89 links = driver.find_elements_by_xpath('//table//tbody/tr/td/a')
90 #scroll to the n-th link, it may be out of the initially visible area
91 actions.move_to_element(links[index]).perform()
92 links[index].click()
93 #scrape the data on the new page and get back with the following command
94 driver.execute_script("window.history.go(-1)") #you can alternatevely use this as well: driver.back()
95 WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table//tbody/tr/td/a")))
96 time.sleep(1)
97
QUESTION
I am trying to fetch data from api and show in list or card view
Asked 2022-Jan-12 at 11:34enter code here
#in extractedData data is fetched but i am getting an error saying I/flutter ( 7967): type '(dynamic, dynamic) => Null' is not a subtype of type '(dynamic) => dynamic' of 'f'
E/flutter ( 7967): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type '(dynamic, dynamic) => Null' is not a subtype of type '(dynamic) => dynamic' of 'f'
E/flutter ( 7967): #0 CategoryModels.fetchData (package:apiwork/models/category_model.dart:64:7)
E/flutter ( 7967):
1 Future<void> fetchData() async{
2 var url = "my api goes here..........";
3 try{
4 final response = await http.get(Uri.parse(url));
5 final extractedData = json.decode(response.body);
6 final List<CategoryModel> loadedProduct = [];
7 if(extractedData == null){
8 return;
9 }
10 extractedData.forEach((prodId,productData){
11 loadedProduct.add(CategoryModel(
12 id:productData['id'],
13 image:productData['images'],
14 name:productData['name'],
15 ));
16 });
17 _cItems = loadedProduct;
18 notifyListeners();
19 print(_cItems);
20 }catch(e){
21 print(e);
22 throw e;
23 }
24 }
25
#this is my home.dart
1 Future<void> fetchData() async{
2 var url = "my api goes here..........";
3 try{
4 final response = await http.get(Uri.parse(url));
5 final extractedData = json.decode(response.body);
6 final List<CategoryModel> loadedProduct = [];
7 if(extractedData == null){
8 return;
9 }
10 extractedData.forEach((prodId,productData){
11 loadedProduct.add(CategoryModel(
12 id:productData['id'],
13 image:productData['images'],
14 name:productData['name'],
15 ));
16 });
17 _cItems = loadedProduct;
18 notifyListeners();
19 print(_cItems);
20 }catch(e){
21 print(e);
22 throw e;
23 }
24 }
25class HomeScreen extends StatefulWidget {
26 const HomeScreen({Key? key}) : super(key: key);
27
28 @override
29 _HomeScreenState createState() => _HomeScreenState();
30}
31
32class _HomeScreenState extends State<HomeScreen> {
33 bool _selected =false;
34 var _selectedIndex = 1;
35 var _isInit = true;
36 var _isLoading = false;
37
38 @override
39 void didChangeDependencies(){
40 // TODO: implement didChangeDependencies
41 if(_isInit){
42 setState(() {
43 _isLoading = true;
44 });
45 Provider.of<CategoryModels>(context).fetchData();
46 setState(() {
47 _isLoading = false;
48 });
49 }
50 _isInit = false;
51 super.didChangeDependencies();
52 }
53
54 void changeAnimatedContainerHeight(bool index){
55 setState(() {
56 _selected = index;
57 _selected = !_selected;
58 print(_selected);
59 });
60 }
61
62 void onTapped(var index){
63 setState(() {
64 _selectedIndex = index;
65 });
66 }
67 final List<String> imageList = [
68 'https://th.bing.com/th/id/OIP.ayY5Ok1_cnPjwSRxEQERuwHaEO?pid=ImgDet&w=698&h=399&rs=1',
69 'https://2qcolg3kl2ha3kfo912rzv2v-wpengine.netdna-ssl.com/wp-content/uploads/sites/8/2017/01/food-1400x550.jpg',
70 'https://th.bing.com/th/id/OIP.qIMnTRibgveVBeUXxEQwngHaE1?pid=ImgDet&w=1024&h=669&rs=1'
71 ];
72
73
74 @override
75 Widget build(BuildContext context) {
76
77
78 return GestureDetector(
79 onTap: (){
80 FocusManager.instance.primaryFocus?.unfocus();
81 },
82
83 child: Scaffold(
84 resizeToAvoidBottomInset: false,
85 appBar: AppBar(
86 backgroundColor: Colors.transparent,
87 leading: const Icon(Icons.location_on_outlined,color: Colors.black,),
88 // title: const Text('Chitwan',style: TextStyle(color: Colors.black),),
89 elevation: 0,
90 actions: [
91 Padding(
92 padding: const EdgeInsets.only(right: 150.0,top: 5.0),
93 child: DropdownButton(
94 value:_selectedIndex,
95 items:const [
96 DropdownMenuItem(
97 child: Text("Chitwan"),
98 value: 1,
99 ),
100 DropdownMenuItem(
101 child: Text("Kathmandu"),
102 value: 2,
103 ),
104 DropdownMenuItem(
105 child: Text("Pokhara"),
106 value: 3,
107 ),
108 DropdownMenuItem(
109 child: Text("Butwal"),
110 value: 4,
111 ),
112 DropdownMenuItem(
113 child: Text("Hetauda"),
114 value: 5,
115 ),
116 ],
117 onChanged: onTapped,
118 ),
119 ),
120 // PopupMenuButton(itemBuilder: (BuildContext context){
121 // return[
122 // PopupMenuItem(child: InkWell(
123 // onTap: (){},
124 // child: Text("Chitwan"),
125 // )
126 // ),
127 // PopupMenuItem(child: InkWell(
128 // onTap: (){},
129 // child: Text("Kathmandu"),
130 // )
131 // ),
132 // PopupMenuItem(child: InkWell(
133 // onTap: (){},
134 // child: Text("Pokhara"),
135 // )
136 // ),
137 // PopupMenuItem(child: InkWell(
138 // onTap: (){},
139 // child: Text("Butwal"),
140 // )
141 // ),
142 // PopupMenuItem(child: InkWell(
143 // onTap: (){},
144 // child: Text("Hetauda"),
145 // )
146 // ),
147 // ];
148 // }),
149 IconButton(onPressed: (){
150 Provider.of<AuthProvider>(context,listen: false).logout(context);
151 }, icon: const Icon(Icons.person,color: Colors.black,)),
152 IconButton(onPressed: (){}, icon: const Icon(Icons.shopping_cart_outlined,color: Colors.black,)),
153 ],
154 ),
155 // drawer: AppDrawer(),
156 // body:BottomNavigation()
157 body: SingleChildScrollView(
158 scrollDirection: Axis.vertical,
159 child: Column(
160 children: [
161 Form(
162 child: Padding(
163 padding: const EdgeInsets.only(left:2.0),
164 child: Container(
165 height: 45.0,
166 width: 380.0,
167 decoration:const BoxDecoration(
168 color: Color(0xFFF2F3F7),
169 ),
170 child: TextFormField(
171 decoration: const InputDecoration(
172 border: OutlineInputBorder(
173 borderSide: BorderSide.none,
174 ),
175 icon: Padding(
176 padding: EdgeInsets.only(left: 5.0),
177 child: Icon(Icons.search),
178 ),
179 hintText:'Hi, how can i help you?',
180 hintStyle: TextStyle(fontSize: 14.0)
181 ),
182 ),
183 ),
184 ),
185 ),
186 // const SizedBox(height: 10.0),
187 AnimatedContainer(
188 height:_selected?220:140,
189 decoration:const BoxDecoration(
190 borderRadius: BorderRadius.only(bottomLeft: Radius.circular(40.0),bottomRight: Radius.circular(20.0)),
191 color: Colors.white,
192 ),
193 duration: const Duration(seconds: 1),
194 curve: Curves.fastOutSlowIn,
195 child: Column(
196 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
197 children: [
198 const Expanded(
199 child: SizedBox(
200 height:100.0,
201 child: Padding(
202 padding: EdgeInsets.only(top: 20.0),
203 child: CategoryGrid(),
204 ),
205 ),
206 ),
207 IconButton(onPressed:(){
208 changeAnimatedContainerHeight(_selected);
209 }, icon:Icon(_selected?Icons.expand_less:Icons.expand_more),color:Colors.black12,iconSize: 30.0,),
210 ],
211 ),
212 ),
213 const SizedBox(height: 10.0),
214
215 CarouselSlider(
216 items:imageList.map((e) =>ClipRRect(
217 borderRadius: BorderRadius.circular(8.0),
218 child: Stack(
219 fit: StackFit.expand,
220 children: [
221 Padding(
222 padding: const EdgeInsets.all(15.0),
223 child: Image.network(e,fit: BoxFit.cover),
224 )
225 ],
226 ),
227 ) ).toList()
228 , options: CarouselOptions(viewportFraction: 1,height: 140.0,autoPlay: true,autoPlayAnimationDuration: const Duration(milliseconds: 800),),),
229
230 const SizedBox(height: 10.0),
231
232 Row(
233 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
234 children:[
235 const Padding(
236 padding:EdgeInsets.only(right: 0.0),
237 child: Text("Today's Special",style: TextStyle(fontWeight: FontWeight.bold),),
238 ),
239 Padding(
240 padding: const EdgeInsets.only(left: 170.0),
241 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
242 ),
243 const Padding(
244 padding: EdgeInsets.only(right: 20.0),
245 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
246 ),
247 ],
248 ),
249
250 const SizedBox(height: 10.0),
251
252 Row(
253 children: const [
254 Expanded(
255 child: SizedBox(
256 height:150.0,
257 child: Padding(
258 padding: EdgeInsets.only(left: 0),
259 child:TodaySpecialGrid(),
260 ),
261 ),
262 )
263 ],
264 ),
265
266 const SizedBox(height: 10.0),
267
268 Row(
269 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
270 children:[
271 const Padding(
272 padding:EdgeInsets.only(right: 0.0),
273 child: Text("Our Partners",style: TextStyle(fontWeight: FontWeight.bold),),
274 ),
275 Padding(
276 padding: const EdgeInsets.only(left: 170.0),
277 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
278 ),
279 const Padding(
280 padding: EdgeInsets.only(right: 20.0),
281 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
282 ),
283 ],
284 ),
285
286 const SizedBox(height: 10.0),
287 Row(
288 children: const [
289 Expanded(
290 child: SizedBox(
291 height:180.0,
292 child: Padding(
293 padding: EdgeInsets.only(left: 8.0),
294 child:OurPartnersGrid(),
295 ),
296 ),
297 )
298 ],
299 ),
300
301
302 const SizedBox(height: 10.0),
303
304 Row(
305 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
306 children:[
307 const Padding(
308 padding:EdgeInsets.only(right: 0.0),
309 child: Text("Our Hotels",style: TextStyle(fontWeight: FontWeight.bold),),
310 ),
311 Padding(
312 padding: const EdgeInsets.only(left: 170.0),
313 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
314 ),
315 const Padding(
316 padding: EdgeInsets.only(right: 20.0),
317 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
318 ),
319 ],
320 ),
321
322 const SizedBox(height: 10.0),
323 Row(
324 children: const [
325 Expanded(
326 child: SizedBox(
327 height:180.0,
328 child: Padding(
329 padding: EdgeInsets.only(left: 8.0),
330 child:OurHotelGrid(),
331 ),
332 ),
333 )
334 ],
335 ),
336
337 const SizedBox(height: 10.0),
338
339 Row(
340 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
341 children:[
342 const Padding(
343 padding:EdgeInsets.only(right: 0.0),
344 child: Text("New Products",style: TextStyle(fontWeight: FontWeight.bold),),
345 ),
346 Padding(
347 padding: const EdgeInsets.only(left: 170.0),
348 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
349 ),
350 const Padding(
351 padding: EdgeInsets.only(right: 20.0),
352 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
353 ),
354 ],
355 ),
356
357 const SizedBox(height: 10.0),
358 Row(
359 children: const [
360 Expanded(
361 child: SizedBox(
362 height:180.0,
363 child: Padding(
364 padding: EdgeInsets.only(left: 8.0),
365 child:NewProductGrid(),
366 ),
367 ),
368 )
369 ],
370 ),
371
372 const SizedBox(height: 10.0),
373 Row(
374 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
375 children:[
376 const Padding(
377 padding:EdgeInsets.only(right: 0.0),
378 child: Text("Vegetables",style: TextStyle(fontWeight: FontWeight.bold),),
379 ),
380 Padding(
381 padding: const EdgeInsets.only(left: 170.0),
382 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
383 ),
384 const Padding(
385 padding: EdgeInsets.only(right: 20.0),
386 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
387 ),
388 ],
389 ),
390
391 const SizedBox(height: 10.0),
392 Row(
393 children: const [
394 Expanded(
395 child: SizedBox(
396 height:500.0,
397 child: Padding(
398 padding: EdgeInsets.only(left: 8.0),
399 child:VegetableGrid(),
400 ),
401 ),
402 )
403 ],
404 ),
405 // const BottomNavigation()
406 ]),
407 ),
408
409 ),
410 );
411 }
412}
413
ANSWER
Answered 2022-Jan-12 at 11:34I think this might fix your issue:
1 Future<void> fetchData() async{
2 var url = "my api goes here..........";
3 try{
4 final response = await http.get(Uri.parse(url));
5 final extractedData = json.decode(response.body);
6 final List<CategoryModel> loadedProduct = [];
7 if(extractedData == null){
8 return;
9 }
10 extractedData.forEach((prodId,productData){
11 loadedProduct.add(CategoryModel(
12 id:productData['id'],
13 image:productData['images'],
14 name:productData['name'],
15 ));
16 });
17 _cItems = loadedProduct;
18 notifyListeners();
19 print(_cItems);
20 }catch(e){
21 print(e);
22 throw e;
23 }
24 }
25class HomeScreen extends StatefulWidget {
26 const HomeScreen({Key? key}) : super(key: key);
27
28 @override
29 _HomeScreenState createState() => _HomeScreenState();
30}
31
32class _HomeScreenState extends State<HomeScreen> {
33 bool _selected =false;
34 var _selectedIndex = 1;
35 var _isInit = true;
36 var _isLoading = false;
37
38 @override
39 void didChangeDependencies(){
40 // TODO: implement didChangeDependencies
41 if(_isInit){
42 setState(() {
43 _isLoading = true;
44 });
45 Provider.of<CategoryModels>(context).fetchData();
46 setState(() {
47 _isLoading = false;
48 });
49 }
50 _isInit = false;
51 super.didChangeDependencies();
52 }
53
54 void changeAnimatedContainerHeight(bool index){
55 setState(() {
56 _selected = index;
57 _selected = !_selected;
58 print(_selected);
59 });
60 }
61
62 void onTapped(var index){
63 setState(() {
64 _selectedIndex = index;
65 });
66 }
67 final List<String> imageList = [
68 'https://th.bing.com/th/id/OIP.ayY5Ok1_cnPjwSRxEQERuwHaEO?pid=ImgDet&w=698&h=399&rs=1',
69 'https://2qcolg3kl2ha3kfo912rzv2v-wpengine.netdna-ssl.com/wp-content/uploads/sites/8/2017/01/food-1400x550.jpg',
70 'https://th.bing.com/th/id/OIP.qIMnTRibgveVBeUXxEQwngHaE1?pid=ImgDet&w=1024&h=669&rs=1'
71 ];
72
73
74 @override
75 Widget build(BuildContext context) {
76
77
78 return GestureDetector(
79 onTap: (){
80 FocusManager.instance.primaryFocus?.unfocus();
81 },
82
83 child: Scaffold(
84 resizeToAvoidBottomInset: false,
85 appBar: AppBar(
86 backgroundColor: Colors.transparent,
87 leading: const Icon(Icons.location_on_outlined,color: Colors.black,),
88 // title: const Text('Chitwan',style: TextStyle(color: Colors.black),),
89 elevation: 0,
90 actions: [
91 Padding(
92 padding: const EdgeInsets.only(right: 150.0,top: 5.0),
93 child: DropdownButton(
94 value:_selectedIndex,
95 items:const [
96 DropdownMenuItem(
97 child: Text("Chitwan"),
98 value: 1,
99 ),
100 DropdownMenuItem(
101 child: Text("Kathmandu"),
102 value: 2,
103 ),
104 DropdownMenuItem(
105 child: Text("Pokhara"),
106 value: 3,
107 ),
108 DropdownMenuItem(
109 child: Text("Butwal"),
110 value: 4,
111 ),
112 DropdownMenuItem(
113 child: Text("Hetauda"),
114 value: 5,
115 ),
116 ],
117 onChanged: onTapped,
118 ),
119 ),
120 // PopupMenuButton(itemBuilder: (BuildContext context){
121 // return[
122 // PopupMenuItem(child: InkWell(
123 // onTap: (){},
124 // child: Text("Chitwan"),
125 // )
126 // ),
127 // PopupMenuItem(child: InkWell(
128 // onTap: (){},
129 // child: Text("Kathmandu"),
130 // )
131 // ),
132 // PopupMenuItem(child: InkWell(
133 // onTap: (){},
134 // child: Text("Pokhara"),
135 // )
136 // ),
137 // PopupMenuItem(child: InkWell(
138 // onTap: (){},
139 // child: Text("Butwal"),
140 // )
141 // ),
142 // PopupMenuItem(child: InkWell(
143 // onTap: (){},
144 // child: Text("Hetauda"),
145 // )
146 // ),
147 // ];
148 // }),
149 IconButton(onPressed: (){
150 Provider.of<AuthProvider>(context,listen: false).logout(context);
151 }, icon: const Icon(Icons.person,color: Colors.black,)),
152 IconButton(onPressed: (){}, icon: const Icon(Icons.shopping_cart_outlined,color: Colors.black,)),
153 ],
154 ),
155 // drawer: AppDrawer(),
156 // body:BottomNavigation()
157 body: SingleChildScrollView(
158 scrollDirection: Axis.vertical,
159 child: Column(
160 children: [
161 Form(
162 child: Padding(
163 padding: const EdgeInsets.only(left:2.0),
164 child: Container(
165 height: 45.0,
166 width: 380.0,
167 decoration:const BoxDecoration(
168 color: Color(0xFFF2F3F7),
169 ),
170 child: TextFormField(
171 decoration: const InputDecoration(
172 border: OutlineInputBorder(
173 borderSide: BorderSide.none,
174 ),
175 icon: Padding(
176 padding: EdgeInsets.only(left: 5.0),
177 child: Icon(Icons.search),
178 ),
179 hintText:'Hi, how can i help you?',
180 hintStyle: TextStyle(fontSize: 14.0)
181 ),
182 ),
183 ),
184 ),
185 ),
186 // const SizedBox(height: 10.0),
187 AnimatedContainer(
188 height:_selected?220:140,
189 decoration:const BoxDecoration(
190 borderRadius: BorderRadius.only(bottomLeft: Radius.circular(40.0),bottomRight: Radius.circular(20.0)),
191 color: Colors.white,
192 ),
193 duration: const Duration(seconds: 1),
194 curve: Curves.fastOutSlowIn,
195 child: Column(
196 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
197 children: [
198 const Expanded(
199 child: SizedBox(
200 height:100.0,
201 child: Padding(
202 padding: EdgeInsets.only(top: 20.0),
203 child: CategoryGrid(),
204 ),
205 ),
206 ),
207 IconButton(onPressed:(){
208 changeAnimatedContainerHeight(_selected);
209 }, icon:Icon(_selected?Icons.expand_less:Icons.expand_more),color:Colors.black12,iconSize: 30.0,),
210 ],
211 ),
212 ),
213 const SizedBox(height: 10.0),
214
215 CarouselSlider(
216 items:imageList.map((e) =>ClipRRect(
217 borderRadius: BorderRadius.circular(8.0),
218 child: Stack(
219 fit: StackFit.expand,
220 children: [
221 Padding(
222 padding: const EdgeInsets.all(15.0),
223 child: Image.network(e,fit: BoxFit.cover),
224 )
225 ],
226 ),
227 ) ).toList()
228 , options: CarouselOptions(viewportFraction: 1,height: 140.0,autoPlay: true,autoPlayAnimationDuration: const Duration(milliseconds: 800),),),
229
230 const SizedBox(height: 10.0),
231
232 Row(
233 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
234 children:[
235 const Padding(
236 padding:EdgeInsets.only(right: 0.0),
237 child: Text("Today's Special",style: TextStyle(fontWeight: FontWeight.bold),),
238 ),
239 Padding(
240 padding: const EdgeInsets.only(left: 170.0),
241 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
242 ),
243 const Padding(
244 padding: EdgeInsets.only(right: 20.0),
245 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
246 ),
247 ],
248 ),
249
250 const SizedBox(height: 10.0),
251
252 Row(
253 children: const [
254 Expanded(
255 child: SizedBox(
256 height:150.0,
257 child: Padding(
258 padding: EdgeInsets.only(left: 0),
259 child:TodaySpecialGrid(),
260 ),
261 ),
262 )
263 ],
264 ),
265
266 const SizedBox(height: 10.0),
267
268 Row(
269 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
270 children:[
271 const Padding(
272 padding:EdgeInsets.only(right: 0.0),
273 child: Text("Our Partners",style: TextStyle(fontWeight: FontWeight.bold),),
274 ),
275 Padding(
276 padding: const EdgeInsets.only(left: 170.0),
277 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
278 ),
279 const Padding(
280 padding: EdgeInsets.only(right: 20.0),
281 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
282 ),
283 ],
284 ),
285
286 const SizedBox(height: 10.0),
287 Row(
288 children: const [
289 Expanded(
290 child: SizedBox(
291 height:180.0,
292 child: Padding(
293 padding: EdgeInsets.only(left: 8.0),
294 child:OurPartnersGrid(),
295 ),
296 ),
297 )
298 ],
299 ),
300
301
302 const SizedBox(height: 10.0),
303
304 Row(
305 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
306 children:[
307 const Padding(
308 padding:EdgeInsets.only(right: 0.0),
309 child: Text("Our Hotels",style: TextStyle(fontWeight: FontWeight.bold),),
310 ),
311 Padding(
312 padding: const EdgeInsets.only(left: 170.0),
313 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
314 ),
315 const Padding(
316 padding: EdgeInsets.only(right: 20.0),
317 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
318 ),
319 ],
320 ),
321
322 const SizedBox(height: 10.0),
323 Row(
324 children: const [
325 Expanded(
326 child: SizedBox(
327 height:180.0,
328 child: Padding(
329 padding: EdgeInsets.only(left: 8.0),
330 child:OurHotelGrid(),
331 ),
332 ),
333 )
334 ],
335 ),
336
337 const SizedBox(height: 10.0),
338
339 Row(
340 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
341 children:[
342 const Padding(
343 padding:EdgeInsets.only(right: 0.0),
344 child: Text("New Products",style: TextStyle(fontWeight: FontWeight.bold),),
345 ),
346 Padding(
347 padding: const EdgeInsets.only(left: 170.0),
348 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
349 ),
350 const Padding(
351 padding: EdgeInsets.only(right: 20.0),
352 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
353 ),
354 ],
355 ),
356
357 const SizedBox(height: 10.0),
358 Row(
359 children: const [
360 Expanded(
361 child: SizedBox(
362 height:180.0,
363 child: Padding(
364 padding: EdgeInsets.only(left: 8.0),
365 child:NewProductGrid(),
366 ),
367 ),
368 )
369 ],
370 ),
371
372 const SizedBox(height: 10.0),
373 Row(
374 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
375 children:[
376 const Padding(
377 padding:EdgeInsets.only(right: 0.0),
378 child: Text("Vegetables",style: TextStyle(fontWeight: FontWeight.bold),),
379 ),
380 Padding(
381 padding: const EdgeInsets.only(left: 170.0),
382 child: GestureDetector(onTap: (){},child: const Text("More",style: TextStyle(color: Color(0xFFE10A35),fontWeight: FontWeight.w600),)),
383 ),
384 const Padding(
385 padding: EdgeInsets.only(right: 20.0),
386 child: Icon(Icons.chevron_right,color: Color(0xFFE10A35),),
387 ),
388 ],
389 ),
390
391 const SizedBox(height: 10.0),
392 Row(
393 children: const [
394 Expanded(
395 child: SizedBox(
396 height:500.0,
397 child: Padding(
398 padding: EdgeInsets.only(left: 8.0),
399 child:VegetableGrid(),
400 ),
401 ),
402 )
403 ],
404 ),
405 // const BottomNavigation()
406 ]),
407 ),
408
409 ),
410 );
411 }
412}
413 extractedData.forEach((element){
414 loadedProduct.add(CategoryModel(
415 id:element['id'],
416 image:element!['images'],
417 name:element['name'],
418 ));
419
Let me know if you have any more issues.
QUESTION
Execute two functions with one button click
Asked 2021-Dec-31 at 01:28I'm having a time trying to figure this one out. First, let me say I'm a total javascript novice, but I haven't figured this out. I want to run two separate functions, both referencing the value in the search box created in the code. The idea is, the script will search for the value in the search box, opening up 2 new tabs, each searching the value accompanied by different secondary terms prescribed in the code. What do I need to get this script to run?
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7 <title>Programmable Search Engine Two</title>
8 <link rel="stylesheet" href="style.css" />
9 </head>
10 <body>
11 <section>
12 <div class="main">
13 <div class="searchBox">
14 <input type="text" name="" class="query" value="" />
15 </div>
16 <div class="button">
17 <button class="searchBtn">Search</button>
18 </div>
19 </div>
20 </section>
21
22<script type="text/javascript">
23
24let query = document.querySelector(".query");
25 let searchBtn = document.querySelector(".searchBtn");
26
27 searchBtn.onclick = "function One(); function Two();"
28
29 function One() {
30 let url = "https://www.google.com/search?q=" + query.value + " " + "hotels";
31 window.open(url, (target = "blank"))
32
33 },
34
35 function Two() {
36 let url = "https://www.google.com/search?q=" + query.value + " " + "hotels";
37 window.open(url, (target = "blank"))
38
39 };
40
41</script>
42
43 </body>
44</html>
45
46
ANSWER
Answered 2021-Dec-31 at 01:05You should change
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7 <title>Programmable Search Engine Two</title>
8 <link rel="stylesheet" href="style.css" />
9 </head>
10 <body>
11 <section>
12 <div class="main">
13 <div class="searchBox">
14 <input type="text" name="" class="query" value="" />
15 </div>
16 <div class="button">
17 <button class="searchBtn">Search</button>
18 </div>
19 </div>
20 </section>
21
22<script type="text/javascript">
23
24let query = document.querySelector(".query");
25 let searchBtn = document.querySelector(".searchBtn");
26
27 searchBtn.onclick = "function One(); function Two();"
28
29 function One() {
30 let url = "https://www.google.com/search?q=" + query.value + " " + "hotels";
31 window.open(url, (target = "blank"))
32
33 },
34
35 function Two() {
36 let url = "https://www.google.com/search?q=" + query.value + " " + "hotels";
37 window.open(url, (target = "blank"))
38
39 };
40
41</script>
42
43 </body>
44</html>
45
46searchBtn.onclick = "function One(); function Two();"
47
to
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7 <title>Programmable Search Engine Two</title>
8 <link rel="stylesheet" href="style.css" />
9 </head>
10 <body>
11 <section>
12 <div class="main">
13 <div class="searchBox">
14 <input type="text" name="" class="query" value="" />
15 </div>
16 <div class="button">
17 <button class="searchBtn">Search</button>
18 </div>
19 </div>
20 </section>
21
22<script type="text/javascript">
23
24let query = document.querySelector(".query");
25 let searchBtn = document.querySelector(".searchBtn");
26
27 searchBtn.onclick = "function One(); function Two();"
28
29 function One() {
30 let url = "https://www.google.com/search?q=" + query.value + " " + "hotels";
31 window.open(url, (target = "blank"))
32
33 },
34
35 function Two() {
36 let url = "https://www.google.com/search?q=" + query.value + " " + "hotels";
37 window.open(url, (target = "blank"))
38
39 };
40
41</script>
42
43 </body>
44</html>
45
46searchBtn.onclick = "function One(); function Two();"
47searchBtn.addEventListener('click', function() {
48 One();
49 Two();
50})
51
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Hotels
Tutorials and Learning Resources are not available at this moment for Hotels