Share
Go down
geek
Posts : 4
Join date : 2009-08-10

How to get the element path like href

on Mon Aug 10, 2009 7:31 pm
hi, i want to get the button's href value,

this should return a href like "http://sitename/dev/auction/auction/view/id/ "

can anyone help me that how can i get the page elements urls.



Regards:
Geek
avatar
Advisor
------------------------
------------------------
Posts : 383
Join date : 2009-07-30
Location : India
http://seleniumforum.forumotion.net

Re: How to get the element path like href

on Tue Aug 11, 2009 11:13 am
Hi,

First of all welcome and thanks to join this forum. Very Happy

Now the solution for your problem is:

storeAttribute ( attributeLocator, variableName )


Example:

In IDE:
storeAttribute| locatorOfYourButton@href| VariableName [This will store the href or link of that button into the variableName and now you can use this variable as per requirement ]
type| textFieldLocator| ${variableName}

In RC:
I am telling you snippet of code in java.
String variableName = getAttribute(locatorOfYourButton@href); [Similarly use this variable anywhere you want].


Hope this will help you solve your problem. Best Of Luck.

Bye
geek
Posts : 4
Join date : 2009-08-10

Re: How to get the element path like href

on Tue Aug 11, 2009 1:04 pm
hi Admin, thanks to immediate reply on my query,
well i have tried this , but my query is little bit more complicated now,

well i have a listing items on the page, and every listing item has its own unique id, which is enclosed in a href link,

please take a look on following code , that will give you more detail understanding of my issue
//////////////////////////// Start //////////////////////////////

<li class="item">
<p class="product-image">
</p>
<h5>
</h5>
<div class="current_bid">
<span class="left">Current Bid:</span>
<button class="form-button" onclick="setLocation('http://www.xyz.com/dev/auction/auction/view/id/753/')">
</button>
<strong>
</strong>
</div>
<div class="bids_number">
</div>
<div class="time_remaining">
</div>
</li>
//////////////// from here again a new listing item container starts to fill the next item detail on the page.
<li class="item">
<p class="product-image">
</p>
<h5>
</h5>
<div class="current_bid">
<span class="left">Current Bid:</span>
<button class="form-button" onclick="setLocation('http://www.xyz.com/dev/auction/auction/view/id/755/')">
</button>
<strong>
</strong>
</div>
<div class="bids_number">
</div>
<div class="time_remaining">
</div>

</li>
//////////////// from here again a new listing item container starts to fill the next item detail on the page.

<li class="item">

<p class="product-image">
</p>
<h5>
</h5>
<div class="current_bid">
<span class="left">Current Bid:</span>
<button class="form-button" onclick="setLocation('http://www.xyz.com/dev/auction/auction/view/id/756/')">
</button>
<strong>
</strong>
</div>
<div class="bids_number">
</div>
<div class="time_remaining">
</div>

</li>

</ol>
//////////////////////////// End //////////////////////////////

like i need to get these bold ids number

and in return it will give me
http://www.xyz.com/dev/auction/auction/view/id/753/
http://www.xyz.com/dev/auction/auction/view/id/755/
http://www.xyz.com/dev/auction/auction/view/id/756/

waiting for your reply


best Regards:
Atif mahmood.
avatar
Advisor
------------------------
------------------------
Posts : 383
Join date : 2009-07-30
Location : India
http://seleniumforum.forumotion.net

Re: How to get the element path like href

on Tue Aug 11, 2009 2:16 pm
hi,

It is also work like same , just create a id of that button from selenium ide. You have to find unique name for that and place it like this

storeAttribute | id@onclick| variableName


output: variableName = setLocation('http://www.xyz.com/dev/auction/auction/view/id/756/')

After you have url and you can verify it.
geek
Posts : 4
Join date : 2009-08-10

Re: How to get the element path like href

on Wed Aug 12, 2009 2:22 pm
hi admin,
well i'm not an expert in selenium-rc java . i have just started work on it.

your solution seems like it works but when i try to use this method like

selenium.storeAttribute();

then i'm not able to find that method in my selenium ver.

i'm useing " selenium-remote-control-1.0.1-dist" ver.
would you please tell me what can i do to solve my problem

please reply me as soon as you can , because my project submittion date is very near

thankx

Regards:
geek
geek
Posts : 4
Join date : 2009-08-10

Re: How to get the element path like href

on Wed Aug 12, 2009 4:29 pm
and one thing more i have the attribute like this

" <button class="form-button" onclick="setLocation('http://www.abc.com/dev/auction/auction/view/id/753/')">"

now i want to store this "
http://www.abc.com/dev/auction/auction/view/id/753/" value into a variable.

or

<a title="" href="http://ww.abc.com/dev/auction/auction/view/id/753/"><img height="174" width="174" title="" alt="" src="https://www.abc.com/dev/media/catalog/product/cache/1/small_image/174x174/3594a9c230972d/T/V/TV.jpg"/>


</a>

and i want to this value

" http://ww.abc.com/dev/auction/auction/view/id/753/"

i have tried
selenium.getAttibute("//[@class='form-button']");
selenium.getAttibute("//[@a='title']");


but its of no use


Please take a look on it and tell me how can i get these values.
regards:
GEEK
avatar
Advisor
------------------------
------------------------
Posts : 383
Join date : 2009-07-30
Location : India
http://seleniumforum.forumotion.net

Re: How to get the element path like href

on Wed Aug 12, 2009 5:58 pm
hi,

1. First of all you are using command wrongly. Check the selenium core reference contains all command of selenium. use like this

selenium.storeAttribute(locator @ which value you want);

String variableName =
selenium.storeAttribute(//xyx @ href);

2. Now about second point
String var = selenium.getAttibute("//[@class='form-button']@onclick");
By this command you will get value = setLocation('http://www.abc.com/dev/auction/auction/view/id/753/')remove setLocation from any login in programming language and after that you will have url.

For Second object:
String var2 = selenium.getAttibute("//[@a='title']@href");
after that var2 contain value = href="http://ww.abc.com/dev/auction/auction/view/id/753/


I hope this will help you. Try to do R&d On this you will get through it. best of luck

Bye
Sponsored content

Re: How to get the element path like href

Back to top
Permissions in this forum:
You cannot reply to topics in this forum