The XPath #root-node-position attribute info - xpath

I couldn't find the #root-node-position XPath attribute/selector info. Would you give me a link of where i can read about it? Is it XPath 2.0?
The code (not mine) is ../preceding-sibling::div[1]/div[#root-node-position]/div applied to this HTML:
<div class="left">
<div class='prod2'>
<div class='name'>Dell Latitude D610-1.73 Laptop Wireless Computer
</div>2 GHz Intel Pentium M, 1 GB DDR2 SDRAM, 40 GB
</div>
<div class='prod1'>
<div class='name'>Samsung Chromebook (Wi-Fi, 11.6-Inch)
</div>1.7 GHz, 2 GB DDR3 SDRAM, 16 GB
</div>
</div>
<div class="right">
<div class='price2'>$239.95</div>
<div class='price1 best'>$249.00</div>
</div>
Firstly i fetch a price text under class='right' with this query : //DIV[contains(#class,'best')] and then i apply the above mentioned XPath with #root-node-attribute under class='left' to retrieve the rest of the record info.

In C# this approach can be handy:
XmlDocument docSourceFile = new XmlDocument();
docSourceFile.Load("XML file path goes here");
XmlNode nodRoot = docSourceFile.DocumentElement;
string strAttributeValue = nodRoot .Attributes ["Write Attribute Name Here"].Value;
Generally, in XPath we use like below to get value of attributes of RootNode:
/RootNodeName/#AttributeName
Good Luck.

The #root-node-position is a non-standard XPath attribute that is only
supported by Visual Web Ripper.
You can read more about non-standard XPath methods, attributes and
axis supported by Visual Web Ripper here, only for registered users.

Related

How to get text which has no HTML tag

Following is the HTML:
<div class="ajaxcourseindentfix">
<h3>CPSC 353 - Introduction to Computer Security (3) </h3>
<hr>Security goals, security systems, access controls, networks and security, integrity, cryptography fundamentals, authentication. Attacks: software, network, website; management considerations, security standards in government and industry; security issues in requirements, architecture, design, implementation, testing, operation, maintenance, acquisition, and services.
<br>
<br>Prerequisite: CPSC 253U
<span style="display: none !important"> </span> or CPSC 254
<span style="display: none !important"> </span> and CPSC 351
<span style="display: none !important"> </span>
, declared major/minor in CPSC, CPEN, or CPEI
<br>
</div>
I need to fetch the following text from this HTML:
From Line 6 - or
From Line 7 - and
, declared major/minor in CPSC, CPEN, or CPEI
I am able to get the href [Course number: CPSC 254 etc...] with the following XPath:
# This xpath gives me all the tags followed by h3 and then I iterate through them in my script.
//div[#class='ajaxcourseindentfix']/h3/following-sibling::text()[2]/following-sibling::*
Update
And, then the text with the following XPath:
# This xpath gives me all the text after the h3 tag.
//div[#class='ajaxcourseindentfix']/h3/following-sibling::text()[2]/following-sibling::text()
I need to have these course name/prerequisite in the same way they are at URL 1.
In this approach I am getting all the HREF first, then all text. Is there a better way to achieve this? I don't want to iterate over 2 XPaths to get the HREF first, then Text and after that club them to form the prerequisite string.
1 http://catalog.fullerton.edu/ajax/preview_course.php?catoid=16&coid=99648&show
Try to use below code to get required output:
div = soup.select("div.ajaxcourseindentfix")[0]
" ".join([word for word in div.stripped_strings]).split("Prerequisite: ")[-1]
The output is
'CPSC 253U or CPSC 254 and CPSC 351 , declared major/minor in CPSC, CPEN, or CPEI'

XPath to extract text within br

<div id="t_info" class="tab-pane fade active in tab">
<br><strong>Delivery</strong> <br>
<br><br><br><strong>Model Name</strong> : BP250
<br>
<br>Full HD up-scaling dramatically improves the resolution of any original content to Full HD.
<br>
<br><strong>Barcode</strong> : 8806087225921
<br>
<br><strong>Product Type</strong> : Blu-ray Player<br>
<br>Blu-Ray Disc <br>External <br></div>
I need xpath to capture the barcode value. Location of the barcode varies depending on the description.
I have tried //*[text()='Barcode'] . but i cant capture the value.
In your case you can use next XPath:
(//div[#id="t_info"]/text())[./preceding::strong[text()='Barcode']][1]
Please note that it is mauvais ton (bad manners)

Best practices to load and display a list of images in an hybrid app

I have a Ionic-1 app in which there's a large list that displays images (I use collection-repeat for this).
For now, I ship the images with the app. But the list evolves with time so my app gets the list from a server, then checks if there are new items, and use remote urls for new images.
The list is getting bigger (more tha 300 items), so managing this is quite heavy on the app. Moreover, shipping the images with the app is going to become impossible, because the .apk or .ipa are getting too big.
So I would like to use a better way to manage my images and also a better way to display them dynamically.
Is that possible to call the server images in my collection-repeat and to make it smooth and performant? Is that possible, that once an image has been called, it's saved in the local memory (maybe localStorage) so that the next time the list displayed it's faster ? If yes, how to do this ?
Is that the best way to manage a dynamical list? I would like to hear the best practice for this, for the best UX.
Here's my bit of code:
<div class="boardselection firstScreen" ng-if="transitionFinished">
<ion-item collection-repeat="item in prodataSelect | orderBy:data.sort | filter: data.selectBrand.brand:true | filter: data.selectName.name | filter: generalSearchFunc | filterObj:['brand','modelStrict']" item-width="25%" item-height="35%" item-render-buffer="16">
<a class="optionfuninit item-content" data-proid="{{item.id}}" on-tap="whatToDo(item.id,$event);" ng-class="item.fun == '0' ? 'aNormal' :( item.fun == '1' ? 'aSmallWave' : (item.fun == '2' ? 'aStepUp' : ''))">
<div class="listviewTrophy" ng-if="isWinning(item.id)">
<i class="icon ion-trophy"></i>
</div>
<i class="icon ion-female" ng-show="item.gender == 'female'"></i>
<!-- <p class="flex-caption" fittext fittext-min="10" fittext-max="15" ng-bind="item.modelStrict" >
{{item.modelStrict}}
</p> -->
<div class="listviewtexts flex-caption" ng-class="item.fun == '0' ? 'aNormal' :( item.fun == '1' ? 'aSmallWave' : (item.fun == '2' ? 'aStepUp' : ''))">
<span class="listviewtextsmodel">{{item.modelStrict}}</span>
</div>
<div class="imagebox">
<img class="imageoptionsmodel " ng-src="{{imagesUrls[item.imageName]}}"/>
</div>
</a>
</ion-item>
you can use ionic-cache-src (https://github.com/BenBBear/ionic-cache-src)
it will work like :
or
you can use $ImageCacheFactory to save it in cache,
docs here.

WebDriver Capture Text by XPath

I am attempting to capture a line of text for an automated WebDriver test to use it in a comparison later on. However, I cannot find an XPath that will work with WebDriver. I have used the text() function before to capture text that is not in a tag, but in this instance that is not working. Here is the HTML, note that this text will never be the same, so I cannot use contains or similar functions.
<div id="content" class="center ui-content" data-role="content" role="main">
<div data-iscroll="scroller">
<div class="ui-corner-all ui-controlgroup ui-controlgroup-vertical" data-role="controlgroup">
<a class="ui-btn ui-corner-top ui-btn-hover-c" style="text-align: left" data-role="button" onclick="onDocumentClicked(21228772, "document.php?loan=********&folderseq=0&itemnum=21228772&pageCount=3&imageTypeName=1003 Application - Final&firstInitial=&lastName=")" href="#" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c">
<span class="ui-btn-inner ui-corner-top">
<span class="ui-btn-text">
<img class="checkMark checkMark21228772 notViewedCompletely" width="15" height="15" title="You have not yet viewed this document." src="../images/white_dot.gif"/>
1003 Application - Final. (Jan 11 2012 5:04PM)
</span>
</span>
</a>
In this example, the text I am attempting to capture is: 1003 Application - Final. (Jan 11 2012 5:04PM)
I have inspected the element with Firebug and I have tried the following XPaths with no success.
html/body/div[1]/div[2]/div/div/a[1]/span/span
html/body/div[1]/div[2]/div/div/a[1]/span/span/text()
The WebDriver test is being written in C#.
You can either use this
driver.FindElement(By.XPath(".//div[#id='content']/following-sibling::span[#class='ui-btn-text']")
or
var elem = driver.FindElement(By.Id("Content"));
string text = string.Empty;
if(elem!=null) {
var textElem = elem.FindElement(By.Xpath(".//following-sibling::span[#class='ui-btn-text']"));
if(textElem!=null) text = textElem.Text();
}
I was able to solve this issue by removing the span tags from the XPath.
GetText("html/body/div[3]/div[2]/div/div/a[1]", SelectorType.XPath);
python webdriver code looks something like
driver.find_element_by_xpath("//span[#class='ui-btn-text']").text
But locator may be not uniqe, because I can't see all the code
PS Try to never use locators like html/body/div[1]/div[2]/div/div/a[1]/span/span
Approach:
Find the CSS Selector from the Given DOM
Derived CSS:css=#content div.ui-controlgroup > a[onclick*='onDocumentClicked'] > span > span
Use the C# Library Method to get the Text.

Get Text between two tags using nokogiri

My HTML structure is
<div class="line">
<h2>Header</h2>
<h3>Mailing Address</h3>
2349 Glorem ipsun lorem ipsum CA 95833<br>
<br>
Phone: 111-111-2111 Fax: 111-511-1111<br>
<a onfocus="blur()" target="_blank"" href="">some text</a><br>
<a onfocus="blur()" target="_blank" href="">some address</a><br>
<div><p></p></div>
<h3>Contact(s)</h3>
</div>
The HTML page contains several <div class=line></div> elements. For each div i need to extract Phone and Fax in a array with other data. I tried using
doc.css("div#ctl00_cphContent_divBrowseByMember").each do |div|
div.css("div.line").each do |line|
line.xpath('//text()[preceding-sibling::br and following-sibling::a]').text.strip
end
end
It returns nothing and returns time out error.
If I try as
line.xpath('//text()[preceding-sibling::br and following-sibling::a]')[0].text.strip
will return same Phone and fax for all other divs. Please suggest any other solution that will help me.
The easy way:
phone, fax = line.text.scan /\d{3}-\d{3}-\d{4}/

Resources