I'm currently trying to build a carousel with bootstrap in the frontend.
Generating the slides works great.
<f:if condition="{gallery.rows}">
<f:for each="{gallery.rows}" as="row">
<f:for each="{row.columns}" as="column">
<f:if condition="{column.media}">
<div class="item">
<f:media
file="{column.media}"
width="{column.dimensions.width}"
height="{column.dimensions.height}"
alt="{column.media.alternative}"
title="{column.media.title}"
/>
<div class="carouselText">
<div class="container">
<h1>{column.media.title}</h1>
<f:if condition="{column.media.description}">
<p>
{column.media.description}
<f:if condition="{column.media.link}">
read more
</f:if>
</p>
</f:if>
</div>
</div>
</div>
</f:if>
</f:for>
</f:for>
</f:if>
Now I need the little dots for the controls.
The problem is, that they need to count up like this:
<li data-target="#carousel" data-slide-to="0"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="2"></li>
Using the same f:for loop as I did to generate the slides in combination with the iteration attribute doesn't work because it's nested in row and columns.
Following output with <f:for each="{row.columns}" as="column" iteration='i'>:
<li data-target="#carousel" data-slide-to="0"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="0"></li>
Luckily the gallery array also has an integer in which the amount of images is stored {gallery.count.files} = 3.
There must be an easy way to use for-loops or similar to count up with just an integer and not having an array, right?
In TYPO3v8 and above:
{f:variable(name: 'count', value: 0)}
<!-- perform iteration to any depth, recursive or reverse or whatever -->
<li data-slide-to="{count}">..</li>
{f:variable(name: 'count', value: '{count + 1}')}
In TYPO3v7 and earlier you will need the VHS library and substitute f:variable for v:variable.set and {count + 1} for {count -> v:math.sum(b: 1)}.
Related
I am trying to select an item from a dropdown list in robot framework (using RIDE), but I cannot get the item by variable name.
<div class="chosen-drop">
<div class="chosen-search">
<input type="text" autocomplete="off">
</div>
<ul class="chosen-results">
<li class="active-result" data-option-array-index="0">Geen optie gekozen</li>
<li class="active-result" data-option-array-index="2">ABB</li>
<li class="active-result" data-option-array-index="3">Algem</li>
<li class="active-result" data-option-array-index="4">AOV</li>
<li class="active-result" data-option-array-index="5">AW</li>
<li class="active-result" data-option-array-index="8">AOZ</li>
</ul>
</div>
I can use this and get the result:
Click Element xpath=//*[#id="KEUZE_N_MiddelId_N1010D_chosen"]
Click Element xpath=//*
[#id="KEUZE_N_MiddelId_N1010D_chosen"]/div/ul/li[4]
But the index number can change, so I want to click the element based on the value, in this example 'ABB'. How can I achieve this?
You can Try the following:
Select From List By Label| css=ul.chosen-results| ABB
It is very similar to this SO post but not exact enough to be considered a duplicate. Based on your already achieved results I think this should work for you.
[#id="KEUZE_N_MiddelId_N1010D_chosen"]/div/ul/li[text() = 'ABB']
I'm trying to read Amazon products into scrapy.
Starting from a random category using this XPath:
products = Selector(response).xpath('//div[#class="s-item-container"]')
for product in products:
item = AmzItem()
item['title'] = product.xpath('//a[#class="s-access-detail-page"]/#title').extract()[0]
item['url'] = product.xpath('//a[#class="s-access-detail-page"]/#href').extract()[0]
yield item
('//div[#class="s-item-container"]') returns all the divs with the products on one category page - that's correct.
Now, how would I get the link to the product?
// stands for where ever in the code
a with the #class should select the right class
But I get a:
item['title'] = product.xpath('//a[#class="s-access-detail-page"]/#title').extract()[0]
exceptions.IndexError: list index out of range
So my list matching this XPath must be empty - but I don't understand why?
EDIT:
The HTML would look like that:
<div class="s-item-container" style="height: 343px;">
<div class="a-row a-spacing-base">
<div class="a-column a-span12 a-text-left">
<div class="a-section a-spacing-none a-inline-block s-position-relative">
<a class="a-link-normal a-text-normal" href="https://rads.stackoverflow.com/amzn/click/com/B0105S434A" rel="nofollow noreferrer"><img alt="Product Details" src="http://ecx.images-amazon.com/images/I/41%2BzrAY74UL._AA160_.jpg" onload="viewCompleteImageLoaded(this, new Date().getTime(), 24, false);" class="s-access-image cfMarker" height="160" width="160"></a>
<div class="a-section a-spacing-none a-text-center">
<div class="a-row a-spacing-top-mini">
<a class="a-size-mini a-link-normal a-text-normal" href="https://rads.stackoverflow.com/amzn/click/com/B0105S434A" rel="nofollow noreferrer">
<div class="a-box">
<div class="a-box-inner a-padding-mini"><span class="a-color-secondary">See more choices</span></div>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
<div class="a-row a-spacing-mini">
<div class="a-row a-spacing-none">
<a class="a-link-normal s-access-detail-page a-text-normal" title="Harry Potter Gryffindor School Fancy Robe Cloak Costume And Tie (Size S)" href="https://rads.stackoverflow.com/amzn/click/com/B0105S434A" rel="nofollow noreferrer">
<h2 class="a-size-base a-color-null s-inline s-access-title a-text-normal">Harry Potter Gryffindor School Fancy Robe Cloak Costume And Tie (Size S)</h2>
</a>
</div>
<div class="a-row a-spacing-mini"><span class="a-size-small a-color-secondary">by </span><span class="a-size-small a-color-secondary">Legend</span></div>
</div>
<div class="a-row a-spacing-mini">
<div class="a-row a-spacing-none"><a class="a-size-small a-link-normal a-text-normal" href="http://www.amazon.com/gp/offer-listing/B0105S434A/ref=sr_1_21_olp?s=pet-supplies&ie=UTF8&qid=1435391788&sr=1-21&keywords=pet+supplies&condition=new"><span class="a-size-base a-color-price a-text-bold">$28.99</span><span class="a-letter-space"></span>new<span class="a-letter-space"></span><span class="a-color-secondary">(1 offer)</span><span class="a-letter-space"></span><span class="a-color-secondary a-text-strike"></span></a></div>
</div>
<div class="a-row a-spacing-none"><span name="B0105S434A">
<span class="a-declarative" data-action="a-popover" data-a-popover="{"max-width":"700","closeButton":"false","position":"triggerBottom","url":"/review/widgets/average-customer-review/popover/ref=acr_search__popover?ie=UTF8&asin=B0105S434A&contextId=search&ref=acr_search__popover"}"><i class="a-icon a-icon-star a-star-4"><span class="a-icon-alt">3.9 out of 5 stars</span></i><i class="a-icon a-icon-popover"></i></span></span>
<a class="a-size-small a-link-normal a-text-normal" href="https://rads.stackoverflow.com/amzn/click/com/B0105S434A" rel="nofollow noreferrer">48</a>
</div>
</div>
It should be:
# ------------- The dot makes the query relative to product
product.xpath('.//a[#class="s-access-detail-page"]/#title')
//a[#class="s-access-detail-page"] requires to be exactly class="s-access-detail-page", because xpath works with string but not with meaning :) When you have "multi class ", use contains function
//a[contains(concat(' ', #class, ' '), " s-access-detail-page ")]/#title
I have never run into an issue with being able to select a value in a drop down, so I'm not sure how this is different. First, here is the HTML I'm working with:
<div class="hn-select-content hn-select-expand" ng-class="{'open-to-left':openToLeft, 'expand-to-left':expandToLeft}" ng-transclude="" style="">
<ul class="qty-discount whiteBackground border border-hn-secondary-lt text-small ng-scope" scroll-lock="">
<li float-container="">
<div class="float-cont">
<ul class="text-small">
<li class="selected ng-isolate-scope HN-Item-Opt-Sel" li="" <="" on-option-select="changeQuantity(val)" value="1" option="1" ng-class="{'HN-Item-Opt-Sel selected':atcData.quantity == 1}" hn-select-option="">
<div class="hn-select-option ng-binding">1</div>
</li>
</ul>
</li>
<li float-container="">
<div class="text-hn-red float-cont">
<div scroller="qty-discount" floater="" style="">
<span> 10% Off </span>
</div>
<div></div>
</div>
<ul class="text-small">
<li class="ng-isolate-scope" li="" <="" on-option-select="changeQuantity(val)" value="2" option="2" ng-class="{'HN-Item-Opt-Sel selected':atcData.quantity == 2}" hn-select-option="">
<div class="hn-select-option ng-binding">2</div>
</li>
I want to select a specific option. in this case, I have a variable set for the quantity, and it's set to 2.
This it the code from the step that is failing:
#browser.div(:id, 'hn_modal_contentIV').div(:text, '1').when_present.click
#browser.ul(:class, 'whiteBackground border border-hn-secondary-lt text-small ng-scope').div(:text, quantity).when_present(5).click
#browser.span(:class, 'redText floatRight marginTopOnly3px').wait_until_present(10)
And this is the error I receive:
Watir::Wait::TimeoutError: timed out after 5 seconds, waiting for {:text=>"2", :tag_name=>"div"} to become present
The drop down box opens, I just can't get the value to be selected.
I have tried a few other variations, but none have worked. Any help would be GREATLY appreciated. Hopefully there is something small that I'm just missing.
Thanks!
First, before this code, HTML must have an select list, perhaps this select list have the attribute "display: none", then you can:
browser.execute_script("document.getElementById('[id of this select list ]').style.display = 'block';")
browser.select(:id => '[id of this select]').option(:text => '[text that you need]').select
I am using Scrapy and have run into a few places where it would be nice to use variables, but I can't figure out how. Meaning if I have some long string it would be nice to store it in a variable long_string and then select for it: hxs.select('\\div[#id=long_string]').
I'm sure this is supported by Scrapy and I just can't figure it out as it wouldn't make sense for you to always have to hard-code the string in.
Update:
So for the sample text below I want to extract the div where id="footer":
<div id="footer">
<div id="footer-menu">
<div class="region-footer-menu">
<div id="block-menu-menu-footer-menu" class="block-menu">
<div class="content">
<ul class="menu">
<li class="first leaf">FAQs</li>
<li class="leaf">Media</li>
<li class="leaf">Partners</li>
<li class="last leaf active-trail">Jobs</li>
</ul>
</div>
</div>
<div id="block-block-52" class="block block-block">
<div class="content">
<p>SUPPORT</p>
</div>
</div>
</div>
</div>
</div>
We initialize hxs = HtmlXPathSelector(response) for all the below segments.
The following code selects only the first div:
hxs.select('//div[#id=concat("foot","er")]')
This code selects nothing but gives no error:
hxs.select('//div[#id="foot"+"er"]')
Both of the below code segments select nothing and give no errors:
long_string = "foot"
hxs.select('//div[#id=concat(long_string,"er")]')
hxs.select('//div[#id=long_string]')
I would like to be able to do either of the bottom two methods and return the desired results.
Assuming + works for string concatenation in Scrapy, this should work:
hxs.select('//div[#id="' + long_string + '"]')
I'm not familiar with Scrapy, but I don't think you'll be able to select a div that doesn't exist.
have you tried?
hxs.select('\\div[#id="' + long_string_variable + '"]')
I am trying to access a div in an li array
<ul>
<li class="views-row views-row-1 views-row-odd views-row-first">
<div class="news-item">
</li>
<li class="views-row views-row-2 views-row-even">
<li class="views-row views-row-3 views-row-odd">
<div class="news-item">
<div class="image">
<div class="details with-image">
<h2>
<p class="standfirst">The best two-seat </p>
<div class="meta">
<div class="pub-date">26 April 2012</div>
<div class="topic-bar clearfix">
<div class="topic car_review">review</div>
</div>
</div>
</div>
</div>
</li>
I am trying to access the "div class="topic car_review">car review "and get its text.
The reason I am specifically using that text is that, depending on what the text is it would enter specific steps.
Code that I am using is
#topic = #browser.li(:class => /views-row-#{x}/).div(:class,'news-item').div(:class,'details').div(:class,'meta').div(:class,/topic /).text
The script was working fine before and suddenly it has stopped working and is just not able to get the div(:class,'news-item').
The error message I get is
unable to locate element, using {:class=>"news-item", :tag_name=>"div"} (Watir::Exception::UnknownObjectException)
I tried div(:class => /news-/) but still its just not able to find that element
I am really stuck!!!
I assume that when you are doing li(:class => /views-row-#{x}/), the x means you are iterating over all rows? If so, then your script will fail on the row-2 since it does not contain the news-item div (resulting in the error that you see).
If there is only one of these 'topic car_review' div tags, you can just do:
#topic = #browser.div(:class, 'topic car_review')
Update - Iterating over each LI:
If you need to iterate over each LI, then you could do:
#browser.lis.each do |li|
#topic = li.div(:class, 'topic car_review').text
end