How to write a XPath using the > Operators? - selenium

I am trying to add the item to the cart which price is > (Greater than) the $35 using the below XPath
//div[#class='m-product-mini']//span[contains(text()>'$35.00')]
but using this XPath I am unable to identify the price value, below is the HTML code.
<div class="m-product-mini">
<div data-id="EF_TLR04-1A-P_EF_TLR04-1A">
<!-- main-image -->
<div class="m-product-mini-image">
Quick view
<a href="/bouquet/stunning-statement-bouquet/p_ef_tlr04-1a?skuId=EF_TLR04-1A&zipMin=">
</a>
</div>
<span class="m-product-mini-merchandising-icon">
<img src="new.jpg" alt="New Flower Arrangement by Florence's Flowers & Gifts">
</span>
<h2 class="m-category-flower-link-h2">Stunning Statement Bouquet</h2>
<span>$36.99</span> <span class="priceTag-discount"></span>
</div>
</div>

Try to use below XPath to get required output:
//div[#class='m-product-mini']//span[number(substring-after(text(), '$')) > 35]
Note that you need to
get rid of "$" sign, so substring-after(text(), '$') used
convert result into integer, so number() is used

Related

Show as Html on vuejs

i have json file for translate ( en.json ) and this line :
{
"cancel order": "Hi, How can i <b> Cancel </b> ?",
}
<div class="d-flex align-items-center justify-content-center align-content-center mb-4">
<span class="description col-sm-11 col-md-7 col-lg-10">
{{ $t('cancel order') }}
</span>
</div>
now my result is " Hi, How can i Cancel "
The problem is that the html code does not apply like this code and the tags are displayed exactly without being applied.
You can use the v-html directive to rander raw html.
const htmlcontent = '<h1>Hello</h1>'
<span v-html="htmlcontent">
</span>
https://vuejs.org/guide/essentials/template-syntax.html#raw-html
use this :
<div v-html="$t('cancel order')"></div>
One observation : Using camelCase in property names consider as a best practice. Hence, use cancel order instead of cancel order.
To render your translation as an HTML message and not a static string. You can use v-html.
Template :
<span class="description col-sm-11 col-md-7 col-lg-10" v-html="$t('cancelOrder')"></span>

How to get loop variable suffixed in v-text to get the exact key from data?

I am not able to print the i in passengers.count to v-text="passengers.details.title_i"
I tried wrapping it like this v-text="passengers.details.title_[i]" but doesn't work.
<div v-if="_.size(passengers.details) > 0" v-for="i in passengers.count" :key="i" style="margin-bottom: 15px;">
<h4>Passenger <span v-text="i"></span></h4>
<ul class="list-inline">
<li><label>Title:</label> <span v-text="passengers.details.title_${i}"></span></li>
<li><label>First Name:</label> <span v-text="passengers.details.first_name_${i}"></span></li>
</ul>
</div>
I need v-text="passengers.details.title_[i]" to be read as
v-text="passengers.details.title_1"
You need to use square brackets around the whole property name, not just the number on the end.
You could use backticks:
<span v-text="passengers.details[`title_${i}`]"></span>
Or just concatenation:
<span v-text="passengers.details['title_' + i]"></span>
Not sure why you're using v-text, using {{ ... }} would seem simpler:
<span>{{ passengers.details[`title_${i}`] }}</span>

how to match text in a div element using xpath?

I am trying to locate an xml element in selenium using xpath. It is nested in inside .
I have numbers 3498546 and 3498755 in hand. I need to match these numbers to the numbers listed in elements and locate the specific .
I have tried using various combinations with below:
xpath=//*[#id="tabs"]/ul/li/[contains(div,'3498546')]
But it never worked.
Below is and example html code, I have around 100 listed in
<div id="tabs">
<ul>
<li class="unknown">
<span style="">DELIVERED</span>
<a title="A1" onclick="submitForm('e1:eForm',1);return false;"
class="eLink" href="#">
<div class="c1">"Year 2008
"
<br>"3498546
"
<br>
</div>
<strong>Date: </strong>05/14/2019
</a>
</li>
<li class="unknown">
<span style="">DELIVERED</span>
<a title="A2" onclick="submitForm('e1:eForm',1);return false;"
class="eLink" href="#">
<div class="c1">"Year 2008
"
<br>"3498755
"
<br>
</div>
<strong>Date: </strong>05/14/2019</a>
</li>
</ul>
</div>
I want to be able to locate and click the element which has the text 3498546 or 3498755.
Here is the xpath based on the 3498546.
//div[#class='c1'][contains(normalize-space(.),'3498546')]
you can change the 3498546 value to the required number and use the same. In case you want to get all the elements having numbers and click each one of them then you can use the below xpath.
//div[#id='tabs']//div[#class='c1']
To click() on either of the elements with text as 3498546 or 3498755 you can use the following solutions:
3498546:
Java & partialLinkText:
driver.findElement(By.partialLinkText("3498546")).click();
3498755:
Java & partialLinkText:
driver.findElement(By.partialLinkText("3498755]")).click();
//div[contains(text(),'3498755')]
All you need is to look for the div element that its text contains the numbers you're looking for.

Find WebElement base of text condition

I have an autocomplete list that opens once I type some text into a text field and each element in the list looks like this:
<div class="tt-dataset">
<span class="tt-suggestions" style="display: block;">
<div class="tt-suggestion">
<div style="white-space: normal;">
<p>
<span class="ok-circle"></span>
<strong>name</strong>
<a class="edit" href="bla bla">Edit</a>
</p>
<p>address</p>
<p>phone</p>
<p></p>
</div>
</div>
I get the list this way:
val list = driver.findElements(By.cssSelector("div.tt-dataset div.tt-suggestion"))
In some cases address and phone are empty. When this happens, I want to filter them out in my selector so that the list contains only elements where address and phone are not empty.
Any suggestions?

extracting currency values using scrapy/xpath

Trying to get currency values from some html using scrapy.Code is
links = hxs.select('//a[#class="product-image"]/div[#class="price-box"]//span[#class="price"]/text()').extract()')
And the HTML
<div>
<span>
<sub>
<li class="item first">
<a href="http://www.xtra-vision.ie/dvd-blu-ray/to-rent/new-release/dvd/pitch-perfect-dvd.html" title="Image for Pitch Perfect" class="product-image">
<span class="exclusive-star">
</span>
<img src="http://www.xtra-vision.ie/media/catalog/product/cache/3/small_image/124x173/5b02ab93946615b958c913185aae2414/i/w/iws_5167c10c906b57.33524324.JPG.jpg" alt="Image for Pitch Perfect" />
<h2 class="product-name">Pitch Perfect</h2>
<div class="price-box">
<span class="regular-price" id="product-price-5174">
<span class="price">
€15
<sub class="price-bit">.99</sub>
</span>
</span>
</div>
</a>
</li>
</sub>
</span>
</div>
The resulting price i get is \u20ac15\t\t\t\t\t\t
Is there some way I can extract 15.99 from this html using xpath
I used a combination of xpath and Python so might not be quite what you were after, although this was mainly employed to get rid of the extraneous tabs added to the end of the "price".
price = hxs.select('//span[#class="price"]/text()').extract()
pricebit = hxs.select('//span[#class="price"]/sub[#class="price-bit"]/text()').extract()
totalprice = price + price-bit
totalstr = ''.join(totalprice).replace('\t','')