preg_match get div content with two classes - preg-match

i have these code..
<div class="col-sm-2 title">
Product 1 </div>
I'm new to to this concept.. I want the preg_match code for that..

Related

Put check this checkbox with selenium in ruby programing

I would like to put check this checkbox with selenium in ruby programing.
but i can`t do put check. how should I do?
Now, I make below code.
# code
element = #driver.find_element(:xpath, '//*
[#id="lookCheck10"]/div[1]/div[2]/div[1]/label')
#driver.execute_script("arguments[0].click();", element);
# html
<div class="e-select-box p-look-bike__type-box">
<div class="e-title">
<input type="hidden" name="data[Reserve][types][10]"
id="lookCheck10_" value="0"/><input type="checkbox"
name="data[Reserve][types][10]" id="lookCheck10" value="1"
checked="checked"/> <label
for="lookCheck10">BIKE</label>
</div>
<div class="e-media">
<div class="e-media__body p-look-bike__type-detail">
<p>this is good for family</p>
</div>
<div class="e-media__image p-look-bike__type-image">
<img src="/images/reserve/img_biketype_10.jpg" alt="bike">
</div>
</div>
</div>
I am assuming you want to select a checkbox with label 'BIKE'. For that, use below code-
element = #driver.find_element(:xpath, '//*[#id="lookCheck10"]')
#driver.execute_script("arguments[0].click();", element);

XPath: how to select elements that are related to other on the same level

The question is simple but I don't have enough practice for this case :)
How to get price text value from every div within "block" if we know that we need only item_promo elements.
<div class="block">
<div class="item_promo">item</div>
<div class="item_price">123</div>
</div>
<div class="block">
<div class="item_promo">item</div>
<div class="item_price">456</div>
</div>
<div class="block">
<div class="item_promo">item</div>
<div class="item_price">789</div>
</div>
<div class="block">
<div class="item">item</div>
<div class="item_price">222</div>
</div>
<div class="block">
<div class="item">item</div>
<div class="item_price">333</div>
</div>
You could use the xpath :
//div[#class='block']/*[#class='item_promo']/following-sibling::div[#class='item_price']/text()
You look for div elements that has attribute class with value item_promo and look at its following sibling which has an attribute item_price and grab the text.
This XPath,
//div[div/#class='item_promo']/div[#class='item_price']
will return those item_price class div elements with sibling item_promo class div elements:
<div class="item_price">123</div>
<div class="item_price">456</div>
<div class="item_price">789</div>
This will work regardless of label/price order.

Display data with an AngularJS ng-repeat, in a div, side by side

I have an arraylist from which I need to get values where isActive = true, and to display the data in a <div> tag with the use of ng-repeat.
My problem is that I don't want to keep using ng-repeat every time, while fetching values in each <div> tag.
Is there any generic solution which will iterate only once, and I can see the value in <div>, side by side. Please see this attempt:
enter link description here
I want to see a result like this:
You can write your ng-repeat like below.
Whenever it get isActive true, it will create the div section for this.
<body ng-controller="MainCtrl">
<div ng-repeat="tempData in data">
<div ng-if="tempData.isActive == true" >
<div class="col-xs-12" >
<div class="col-xs-4">Plan Type:</div>
<div class="col-xs-8">{{tempData.plantype}}</div>
</div>
<div class="col-xs-12">
<div class="col-xs-4">Term:</div>
<div class="col-xs-8">{{tempData.term}}</div>
</div>
<div class="col-xs-12">
<div class="col-xs-4">Rate:</div>
<div class="col-xs-8">{{tempData.rate}}</div>
</div>
</div>
</div>
</body>

Is it possible to use non-recursive CSS selectors with the Ruby Nokogiri gem?

If I have HTML like this:
<div id="target">
<div id="a1">
<div class="1">
</div>
<div id="a2">
<div class="2">
<div class="3">
<div class="4">
</div>
<div id="b1">
<div class="1">
</div>
<div id="b2">
<div class="2">
<div class="3">
<div class="4">
</div>
...
...
</div>
...is it possible to select only the first level of div elements from target. So, if I run page.css('#target div').each then I get every single div inside target. If I just want the results to contain the divs with ids ['a1','a2','b1','b2'] is that possible with Nokogiri?
Yes, this is called a child selector
#target > div
Without the > you have a descendant selector, which doesn't care if it's a child, grandchild, great grandchild etc.

Get anchor InnerText in a nested Divs

Html :
<div class="info">
<div class="title">
<div class="{DYNAMIC CLASS NAME}">
Text
</div>
</div>
</div>
<div class="info">
<div class="title">
<div class="{DYNAMIC CLASS NAME}">
Another Text
</div>
</div>
</div>
XPath :
DocumentNode.SelectNodes["//div[#class='info']/div[2]/a"];
How to get a innertext value from nested divs?
Because 3rd div classname is a dynamic.
Thanks.
Using index, like div[2], to get nested <div> is not correct. You should've used div/div instead. Try this way :
DocumentNode.SelectNodes("//div[#class='info']/div[#class='title']/div/a");

Resources