I am trying to collect the values - name, quantity, price per KG and total in HashMap. I can use the following 2 items to collect name and quantity
private By productName = By.xpath("//td//p[#class='product-name']");
private By productQuantity = By.xpath("//td//p[#class='quantity']");
Problem: When I try //td//p[#class='amount'] it ends up selecting 4. A few options I have been experimenting are select the 2nd td related to product name which will give me price per kg //td//p[#class='product-name']/following-sibling:://td[2] or //td//p[#class='product-name']/ancestor::td
None of them are working.Any clue what I can use here? Thanks in advance for your time.
Source:
<tr>
<td><img class="product-image" src="./images/cucumber.jpg" style="width: 50px; height: 50px;"></td>
<td>
<td>
<p class="product-name">Cucumber - 1 Kg</p>
</td>
<p class="quantity">2</p>
</td>
<td>
<p class="amount">48</p>
</td>
<td>
<p class="amount">96</p>
</td>
</tr>
If you want to get value of 96 the use Following xpath
//td[.//p[#class='product-name']]/following::td[2]/p
OR
//td[.//p[#class='product-name']]/following-sibling::td[2]/p
Related
I am new to the skrape.it library and try to extract content of a table.
Is there a way to process every table by it self, so I get a List with all texts of a row in a List with all rows? e.g.: List<List>
My current approach is to get all texts from every td and count all tr and then process these two lists by calculating the index of the required text.
One row looks like this:
<tr role="row">
<td class="grad" style="background:#067A25; width:50px">
<div class="grad_outer">
<span>4c</span>
</div>
</td>
<td class="name">
King Louie
</td>
<td>
Dave
</td>
<td>
11.03.2022
</td>
<td>
12
</td>
<td>
64.2
</td>
</tr>
I also need to extract the background css attribute of each first td tag. How can I do this?
I want to find all elements in the table that match the following conditions:
-div text contains '2019';
-div class='excellent';
here is the HTML code excerpt:
<tr>
<td>Name of Person1</td>
<td>
<div class="testDate">21/12/2019</div>
<div class="excellent"></div>
</td>
</tr>
<tr>
<td>Name of Person2</td>
<td>
<div class="testDate">01/12/2017</div>
</td>
</tr>
I tried this solution:
//tr/td[2][div/text()='21/12/2019'][div[#class='starred']]
but I need the year only and not entirely date.
Use the below xpath.
//tr/td[div[contains(.,'2019')]and div[#class='excellent']]
Screenshot:
I am a developer but new to Prestashop (not really familiar with template because i am not a web developer but getting there..) but just helping my friend manage his website.
I checked the current version is 1.5.6 and am trying to add a new fieled in Product table and add another description input area in the following page.
I had a look at Product.php (classes > product.php), AdminProductsController.php (controllers > admin > adminproductscontroller.php) and Products.tpl (themes > uhu023v15 > products.tpl) but none of them seemed relevant to me. Not sure which files I need to modify. Please help.
You need go to
adminXXXX/themes/default/template/controllers/products/informations.tpl
because this is backend template (product.tpl is frontend template and what customer see when view product)
there You will find
<tr>
<td class="col-left">
{include file="controllers/products/multishop/checkbox.tpl" field="description_short" type="tinymce" multilang="true"}
<label>{l s='Short description:'}<br /></label>
<p class="product_description">({l s='Appears in the product list(s), and on the top of the product page.'})</p>
</td>
<td style="padding-bottom:5px;">
{include file="controllers/products/textarea_lang.tpl"
languages=$languages
input_name='description_short'
input_value=$product->description_short
max=$PS_PRODUCT_SHORT_DESC_LIMIT}
<p class="clear"></p>
</td>
</tr>
<tr>
<td>
**Your HERE** ;)
</td>
</tr>
<tr>
<td class="col-left">
{include file="controllers/products/multishop/checkbox.tpl" field="description" type="tinymce" multilang="true"}
<label>{l s='Description:'}<br /></label>
<p class="product_description">({l s='Appears in the body of the product page'})</p>
</td>
<td style="padding-bottom:5px;">
{include file="controllers/products/textarea_lang.tpl" languages=$languages
input_name='description'
input_value=$product->description
}
<p class="clear"></p>
</td>
</tr>
From there You need to duplicate whole textarea block and find and duplicate according functions (not sure where)
Another problem getting to a particular portion of the HTML to click a link. I need to click the link that is above the Classify Item #, IFW #QA GM 04012014 1424-1, Supplier One
The only part of the TD that I know is "QA GM 04012014 1424". I can get to the table by doing a:
//*[#id='openTasksTable']/tbody
What I'm left with then is an unknown number of TD's all with the same ID. I'm not sure how to find the proper one from that point.
Code:
<table id="openTasksTable" cellspacing="1" cellpadding="1">
<thead>
<tbody>
<tr class="evenRow tableControlDataRow twTableTR">
<td>
Run Task
</td>
<td>Classify Item #, IFW #QA GM 04012014 0911-1, Supplier One</td>
<td>Apr 24, 2014</td>
</tr>
<tr class="oddRow tableControlDataRow twTableTR">
<td>
Run Task
</td>
<td>Classify Item #, IFW #QA GM 04012014 1012-1, Supplier One</td>
<td>Apr 24, 2014</td>
</tr>
<tr class="evenRow tableControlDataRow twTableTR">
<td>
Run Task
</td>
<td>Classify Item #, IFW #QA GM 04012014 1414-1, Supplier One</td>
<td>Apr 24, 2014</td>
</tr>
<tr class="oddRow tableControlDataRow twTableTR">
<td>
Run Task
</td>
<td>Classify Item #, IFW #QA GM 04012014 1420-1, Supplier One</td>
<td>Apr 24, 2014</td>
</tr>
<tr class="evenRow tableControlDataRow twTableTR">
<td>
Run Task
</td>
<td>Classify Item #, IFW #QA GM 04012014 1422-1, Supplier One</td>
<td>Apr 24, 2014</td>
</tr>
<tr class="oddRow tableControlDataRow twTableTR">
<td>
Run Task
</td>
<td>Classify Item #, IFW #QA GM 04012014 1424-1, Supplier One</td>
<td>Apr 24, 2014</td>
</tr>
Thanks!
Greg
The following xpath should work for you:
//td[contains(text(),'QA GM 04012014 1424')]/..//a
It will find only the <a> which is in the same <tr> with <td> you mentioned.
A little bit of background:
The HTML looks like this:
<table>
<thead>
<tr>
<th>Head1</th>
<th>Head2</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span>
<span class="icon">S</span>
"Auto"
</span>
</td>
<td>
<span>
Cost, Time
</span>
</td>
</tr>
</tbody>
</table>
A simple version of the code looks like this: (run in pry)
[69] pry> e = driver.find_element(:xpath, "//table/tbody/tr/td/span")
=> #<Selenium::WebDriver::Element:0x7ba9a4d694458ec id=":wdc:1361791490676">
[70] pry> e.text
=> "SAutomotive"
[71] pry> e = driver.find_element(:xpath, "//table/tbody/tr/td/span[contains(text(),'Auto')]")
Selenium::WebDriver::Error::NoSuchElementError: The element could not be found
from /Users/ben/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.29.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
I have no access to changing the HTML code
Although there is only one row in this table there is the possibility of more being added and I cannot predict the location of the row, this is why i am trying to find it by name
my normal code is:
e = driver.find_element(:xpath, "//table/tbody/tr[td/span[contains(text(),'Auto')]]")
The problem I am having is that I cannot find any way of getting the row in the table by the name given in the text of the first table cell.
Use below xpath
"//table/tbody/tr/td/span[contains(.,'Auto')]"