Jmeter: normalize-space to remove white spaces - jmeter

How do I remove extra spaces in tile ? Using below throws an error as unknown
node:normalize-space. this is the one I tried.
//td[#class="title"]/text()/normalize-space(.)
<html>
<head>
<body>
<table class="secondhead" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="title">
My status Report (ABCDEFGH12160916)
<span style="font-size:14pt;color:#00FF00"> * Live, Billable, CRM *
</span>
</td>
</tr>
</tbody>
</table>
</body>
</head>
</html>

As per XPath functions reference
fn:normalize-space(string)
fn:normalize-space()
Removes leading and trailing spaces from the specified string, and replaces all internal sequences of white space with one and returns the result. If there is no string argument it does the same on the current node
Example: normalize-space(' The XML ')
Result: 'The XML'
So you should be using the following expression instead:
normalize-space(//td[#class="title"]/text())
Check out Using the XPath Extractor in JMeter guide to learn more about dealing with XPath and JSON Path in JMeter

Related

Web Scraping - xPath issue

I need to extract the text 120 from this HTML code:
<section class="details">
<h2>Détails du bien</h2>
<table>
....
<tr>
<td>Surface habitable (m²)</td>
<td class="right" title="120">120 </td>
</tr>
...
</table>
</section>
I used this xpath, but it returns an empty list:
//td[contains(text(),"Surface")]/td[#class="right"]/text()
What am I doing wrong?
Try to use xPath axes:
//td[contains(text(),"Surface")]/following-sibling::td[#class="right"]/text()
This should solve your problem.

Jmeter: Xpath to get text upto certain number of characters

From below snippet I want to get title as My status Report(ABCDEFGH12160916)
I have thousands of titles in my html.
//td[#class="dealertitle"]//text() -- this gets me
My status Report (ABCDEFGH12160916)
* Live, Billable, CRM *
I have also tried
//td[#class="dealertitle"]//text()//substring-before(text(),')')---
Jmeter does not allow me to use substring-before. It says unknown node type
substring-before
Can someone please help me.
I want to get this text till the end - My status Report (ABCDEFGH12160916)
<html>
<head>
<body>
<table class="secondhead" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="title">
My status Report (ABCDEFGH12160916)
<span style="font-size:14pt;color:#00FF00"> * Live, Billable, CRM *
</span>
</td>
</tr>
</tbody>
</table>
</body>
</head>
</html>
//td[#class="dealertitle"]//text()[1]
You have an extra / in your XPath query
Your query:
//td[#class="dealertitle"]//text()
Correct query:
//td[#class="dealertitle"]/text()
Demo:
Explanation: as per XPath Syntax article
/ Selects from the root node
// Selects nodes in the document from the current node that match the selection no matter where they are
See Using the XPath Extractor in JMeter guide for more details on using XPath for correlation in JMeter tests.

How to get all the nodes which are coming after a particular tag using Nokogiri

I want to fetch all the HTML tags which are coming after the particular tag. For example:
<html>
<body>
<p>one</p>
<u><p>Two</p></u>
<b><p>Three</p></b>
<p>Four</p>
<table>
<tr><td>Five</td></tr>
<tr><td>Six</td></tr>
</table>
</body>
</html>
I want all the HTML tags which are coming after <u><p>Two</p></u> using Nokogiri.
My result should be:
<b><p>Three</p></b>
<p>Four</p>
<table>
<tr><td>Five</td></tr>
<tr><td>Six</td></tr>
</table>
The following-sibling XPath axis is what you want here. Your example isn’t valid HTML, and Nokogiri will change it when parsing as HTML making it hard to demonstrate using it, but with this similar code:
<html>
<body>
<p>one</p>
<p>Two</p>
<p>Three</p>
<p>Four</p>
<table>
<tr><td>Five</td></tr>
<tr><td>Six</td></tr>
</table>
</body>
</html>
this XPath expression:
//p[.="Two"]/following-sibling::*
will select this:
<p>Three</p>
<p>Four</p>
<table>
<tr><td>Five</td></tr>
<tr><td>Six</td></tr>
</table>
You might want to use node() instead of *, which will select all text nodes as well as elements (including whitespace only nodes):
<p>Three</p>
<p>Four</p>
<table>
<tr><td>Five</td></tr>
<tr><td>Six</td></tr>
</table>
(There will be some more leading whitespace on each line if you do this, I‘ve removed it here.)

Nokogiri and tables

Am parsing a web page with a standard structure as follows:
<html>
<body>
<table>
<tbody>
<tr class="active">
<td>name1</td>
<td>name2</td>
<td>name3</td>
</tr>
</tbody>
</table>
</body>
</html>
For the life of me, I can't access the 'tbody' or 'tr' elements.
response = open('http://my_url')
node = Nokogiri::HTML(response).css('table')
puts node
Returns
#<Nokogiri::XML::Element:0x8294c08c name="table" attributes=[#<Nokogiri::XML::Attr:0x8294c014 name="id" value="beta-users">] children=[#<Nokogiri::XML::Text:0x82953bc0 "\n">]>
I have tried various tricks but can't seem to dig deeper down to a lower-level child than 'table'.
At best, I can get to the lowest-level Text object by using
node.children
but
node.children.text
returns "\n".
Despite searching for some hours am none the wiser how to sort it out. Any thoughts?
There is a non-closed class value in your sample, it should be:
<html>
<body>
<table>
<tbody>
<tr class="active">
<td>name1</td>
<td>name2</td>
<td>name3</td>
</tr>
</tbody>
</table>
</body>
</html>
After correcting this, you can:
node = Nokogiri::HTML(response).css('table tbody tr td')
node.each {|child| puts child.text}
name1
name2
name3

How to XPATH for Table element which have dynamic Ids

I have to get the XPATH for dynamic Ids . The code look like this
<table width="100%" role="presentation">
<tbody>
<tr>
<tr>
<td id="DWT10" role="presentation">
<div id="zl__TV-main__rows" class="DwtListView-Rows" style="height: 130px; width: 377px;">
<div id="zli__TV-main__654" class="RowDouble RowEven " role="treeitem" tabindex="0" aria-label="Unread, hello everyone, Wilkerson, 12:26 AM" aria-posinset="1" aria-level="1">
My XPATH goes like this :
//div[starts-with(#id='zl__CLV-main') and ./div [contains(#aria-posinset,'1')]]
I am getting:
Could not evaluate XPATH error.
XPAth only works if you have a valid XML source file. In your example there are no closing tags.
Your XPATH is invalid. the start-with function must be changed to
//div[starts-with(#id,'zl__CLV-main')
comma instead of =

Resources