Dynamic xpath using anchor tag - xpath

Can any please help me in finding the dynamic xapth?
I have tried with,
#FindBy(xpath="//a[contains(#href,’friend#/friends/myfriends/friendsrequest’)]")
public WebElement lnk_FrndsSeeAll;
Here is the HTMl code,
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>

you can following xpath, which I'm taking using text in the anchor tag
//a[contains(text(),'See all')]
See all should be constant always, then only above xpath will work

It was working fine with beloew code,
#FindBy(xpath="//a[startswith(#href,'friend#/friends/myfriends/friendsrequest')]‌​‌​")
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>

Related

XPath Query for URL Extraction

I need to extract http://site.ru/ from this code:
<div class="one">
<dl>
<dt class="two">
<span class="name">Site</span>
</dt>
<dd class="three">
<span class="js-pseudo-link" data-url="rAnDoMlEtTeRsAnDnUmBeRs" style>
<a href="http://site.ru/" class rel="nofollow" target="_blank" style> http://site.ru/ </a>
</span>
</dd>
</dl>
</div>
I use this XPath query: //div//dl//dd//span//a/#href
But it doesn't work. It doesn't return anything.
I'm a newbie in XPath.
Unfortunately, the data source you are looking for is an empty span node (class js-pseudo-link). The data-url attribute has the base64 encoded link you want. This node only gets populated after loading. ImportXML for some reason ignores nodes with no text and there's no way to get it not to do that. To get around this, looks like you'll have to write an apps script that can handle empty nodes or just gets the raw HTML code and parse it.

How to properly get the value contained inside a section using XPath?

having the following HTML (snippet grabbed from the web page I wanted to scrape):
<div class="ulListContainer">
<section class="stockUpdater">
<ul class="column4">
<li>
<img src="1.png" alt="">
<strong>
Buy*
</strong>
<strong>
Sell*
</strong>
</li>
<li>
<header>
$USD
</header>
<span class="">
20.90
</span>
<span class="">
23.15
</span>
</li>
</ul>
<ul>...</ul>
</section>
</div>
how do I get the 2nd li 1st span value using XPath? The result should be 20.90.
I have tried the following //div[#class="ulListContainer"]/section/ul[1]/li[2]/span[1] but I am not getting any values. I must said this is being used from a Google Sheet and using the function IMPORTXML (not sure what version of XPath it does uses) can I get some help?
Update
Apparently Google Sheets does not support such "complex" XPath expression since it seems to work fine:
Update 1
As requested I've shared the Google Sheet I am using to test this, here is the link
What you need is :
=IMPORTXML(A1;"//li[contains(text(),'USD')]/span[1]")
Removing section from your original XPath will work too :
=IMPORTXML(A1;"//div[#class='ulListContainer']/ul[1]/li[2]/span[1]")
Try this:
=IMPORTXML("URL","//span[1]")
Change URL to the actual website link/URL

Xpath not just getting parent of html

I am trying to find the xpath for only the parent of a navigation bar. The path which I am trying at the moment is `//a[#class='unselectable'] from this peace of HTML.
`<div class="PrimaryNavigationContainer">
<div class="PrimaryNavigation">
<div class="Menu">
<div>
<a href="http://www.blah.co.uk/brands.aspx" class="unselectable"><span>
Brands</span></a>
<div class="navCol">
<div>
<a class="NoLink unselectable"><span>Shop by Brand</span></a>
<div class="navCol subMenus">
div>
<a href="http://www.blah.co.uk/blah/catlist_bd4.htm" class="unselectable"><span>
blah</span></a>
The xpath seem to be bringing up both the top level cats and sub categories and I am because it is in both but not sure how to single of the parent from the chld. Thanks for any help which you can provide
How about //div[#class="Menu"]/div/a[#class='unselectable']? This way you avoid selecting the a in the subMenus div.

Using ruby and selenium webdriver how I can get class from "container"?

I have the following form:
<div id="PaymentInfoDivContainer" class="checkout-section-container complete">
<div class="checkout-section">
<h3 class="sheen">
<span class="step">2</span>
Payment Information
</h3>
<a class="sc-button-white edit-button" onclick="SC.Checkout.Edit(this);"
href="javascript:;">Edit</a>
<div class="checkout-section-content">
</div>
Using Ruby and selenium webdriver, how I can get (and click) on "edit-button" class ?
As I understand I have to get and store in variable id="PaymentInfoDivContainer" and then use it to find the right class. Any thoughts/ideas?
Thanks
Okay,You can go as below : CSS3 [attribute$=value] Selector
driver.find_element(:css,'a[class$="edit-button"]').click
or
driver.find_element(:css,'div#PaymentInfoDivContainer>div>a').click

handling iframe with capybara ruby

Below is the html code ..
<iframe id="I0_1366100881331" frameborder="0" width="100%">
<div class="ZRa">
<span id="button" class="hAa Qo Bg" tabindex="0" role="button" title="" aria- label="Click here to publicly +1 this." aria-pressed="false">
</div>
</iframe>
In the above scenario, I want to switch into the IFRAME (iframe id="I0_1366100881331") to perform some actions on the SPAN present in that IFRAME. I have tried with most of the cases but no result :(... any one please help.
I want the solution for cucumber using capybara ruby only..
Note: I tried with following code but no result.
page.driver.browser.switch_to.frame "I0_1366100881331"
within_frame(find('<css rule>')) do
<code for dealing with iframe entries>
end
I think you can try to use method:
within_frame 'id' do
<code for dealing with iframe entries>
end
Can have this code:
withinframe((:xpath,"//div")) do
#code
end

Resources