- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
how to store csscount/xpath count in a variable and increment it?
Thu Aug 29, 2013 11:49 pm
- Code:
<td class="datepickerSelected">
<a href="#">
<span>21</span>
</a>
</td>
<td class="">
<a href="#">
This is my code.
what is the csscount/xpath count?
I want to store it in a variable. And selenium should click on the stored link on satisfying a conditon.
Then the count should be incremented(to point the next xpath location).
Selenium should click on the new link.
Please help on this.
Thanks in advance.
- kashyap_guruActive particpant
- Posts : 24
Join date : 2013-10-16
Age : 37
Location : India
Re: how to store csscount/xpath count in a variable and increment it?
Thu Oct 24, 2013 3:52 pm
Firstly you need to store total links you need to visit.
storeXpathCount | //a/@href | totalhref
Then with the help of while loop, you can click on every link.
store | 0 | x
while | storedVars['x']
storeEval | window.document.getElementsByTagName('a').item(${x}).href | href${x}
getEval | storedVars['x']=${x}+1
endWhile
With the above code, you will be able to store all links.
With the below code, you will be able to visit each stored link.
store | 0 | y
while | storedVars['y']
storeEval | storedVars['href${y}'] | link
open | ${link}
verifyLocation | ${link}
getEval | storedVars['y']=${y}+1
endWhile
storeXpathCount | //a/@href | totalhref
Then with the help of while loop, you can click on every link.
store | 0 | x
while | storedVars['x']
storeEval | window.document.getElementsByTagName('a').item(${x}).href | href${x}
getEval | storedVars['x']=${x}+1
endWhile
With the above code, you will be able to store all links.
With the below code, you will be able to visit each stored link.
store | 0 | y
while | storedVars['y']
storeEval | storedVars['href${y}'] | link
open | ${link}
verifyLocation | ${link}
getEval | storedVars['y']=${y}+1
endWhile
- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
Re: how to store csscount/xpath count in a variable and increment it?
Thu Oct 24, 2013 4:02 pm
Thank you very much for help. I will try this.
- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
Re: how to store csscount/xpath count in a variable and increment it?
Thu Oct 24, 2013 4:04 pm
- Code:
I used storeXPathCount to get the set of links matching a specific format. Lets consider the count would be 12. So there are 12 different links available which will have different dates like 20, 21, 22,.....31. I want to store these values of the links in an array and use the values one by one.
Getting the first value from array(i.e. 20).
Check for condition.
If condition fails, increment the array count by 1.(It should be 21).
Again check for condition and increment the array.
This is what I am exactly looking for.
Any update on this would be helpful.
- kashyap_guruActive particpant
- Posts : 24
Join date : 2013-10-16
Age : 37
Location : India
Re: how to store csscount/xpath count in a variable and increment it?
Thu Oct 24, 2013 4:16 pm
You need to identify value of span. With link of href, you need to store value of span in other variable.
If you can paste exact code or portion of code, that will be helpful.
If you can paste exact code or portion of code, that will be helpful.
- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
Re: how to store csscount/xpath count in a variable and increment it?
Thu Oct 24, 2013 4:45 pm
- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
Re: how to store csscount/xpath count in a variable and increment it?
Thu Oct 24, 2013 4:59 pm
I am using this format to get the total no of links available.
//div[@class='datepicker']/div/table/tbody/tr/td/table/tbody[2]/tr/td[@class='' or @class='datepickerSaturday' or @class='datepickerSunday']
Consider total links count would be 12.
I want the values present in these 12 links to be stored in an array.
I should get the first link value(ex:21).
I should click the link containing 21.
//div[@class='datepicker']/div/table/tbody/tr/td/table/tbody[2]/tr/td[@class='' or @class='datepickerSaturday' or @class='datepickerSunday']/aspan[contains(text(), "${value}")]
Check for a certain condition. If condition fails, array should be incremented to point the next array item.
//div[@class='datepicker']/div/table/tbody/tr/td/table/tbody[2]/tr/td[@class='' or @class='datepickerSaturday' or @class='datepickerSunday']
Consider total links count would be 12.
I want the values present in these 12 links to be stored in an array.
I should get the first link value(ex:21).
I should click the link containing 21.
//div[@class='datepicker']/div/table/tbody/tr/td/table/tbody[2]/tr/td[@class='' or @class='datepickerSaturday' or @class='datepickerSunday']/aspan[contains(text(), "${value}")]
Check for a certain condition. If condition fails, array should be incremented to point the next array item.
- kashyap_guruActive particpant
- Posts : 24
Join date : 2013-10-16
Age : 37
Location : India
Re: how to store csscount/xpath count in a variable and increment it?
Fri Oct 25, 2013 12:06 pm
Sorry to say this but i asked you for page code. I mean the code portion you want to fetch links and all.. I need to look into that code. Atleast code from VIEW SOURCE.
- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
Re: how to store csscount/xpath count in a variable and increment it?
Fri Oct 25, 2013 10:04 pm
http://46.staging-cochii-hrd.appspot.com/bookanappointmentv3.do?uniqueKey=8a37ea79-c5b2-4c36-9180-3ec293474aa8
This is the URL
This is the URL
- kashyap_guruActive particpant
- Posts : 24
Join date : 2013-10-16
Age : 37
Location : India
Re: how to store csscount/xpath count in a variable and increment it?
Wed Oct 30, 2013 6:01 pm
Hi, Sorry for late reply.
Below is your complete case to store all time slots available today for all staffs and all services.
Below is your complete case to store all time slots available today for all staffs and all services.
open | http://46.staging-cochii-hrd.appspot.com/bookanappointmentv3.do?uniqueKey=8a37ea79-c5b2-4c36-9180-3ec293474aa8 | |
storeXpathCount | //li/@onclick | totalServices |
store | 1 | m |
while | storedVars['m'] <= storedVars['totalServices'] | |
clickAt | //ul//li[contains(.,"Service${m}")] | |
pause | 3000 | |
storeXpathCount | //li/@onclick | totalStaff |
store | 1 | n |
while | storedVars['n'] <= storedVars['totalStaff'] | |
storeElementPresent | //ul//li[contains(.,"Staff${n}")] | presents |
gotoIf | presents == "" | endcase |
clickAt | //ul//li[contains(.,"Staff${n}")] | |
pause | 3000 | |
store | 1 | x |
while | ${x}<4 | |
if | ${x} == 1 | |
store | 50 | z |
endIf | ||
if | ${x} == 2 | |
store | 18 | z |
endIf | ||
if | ${x} == 3 | |
store | 29 | z |
endIf | ||
if | ${x} == 1 | |
store | Morning | timeslot |
endIf | ||
if | ${x} == 2 | |
store | Afternoon | timeslot |
endIf | ||
if | ${x} == 3 | |
store | Evening | timeslot |
endIf | ||
storeEval | 2 | y |
while | ${y} < ${z} | |
storeEval | ${y} - 1 | time |
storeElementPresent | xpath=id('timesheet')/ul[${x}]/li[${y}]/a | present |
gotoIf | present == "" | endinnerloop |
storeText | xpath=id('timesheet')/ul[${x}]/li[${y}]/a | Service ${m} - Staff${n} - Time Slot - ${timeslot} - ${time} |
label | endinnerloop | |
storeEval | ${y} + 1 | y |
endWhile | ||
storeEval | ${x} + 1 | x |
endWhile | ||
label | endcase | |
clickAt | xpath=id('gt_act')/div[1]/ul/li[3]/span | |
pause | 2000 | |
storeEval | ${n} + 1 | n |
endWhile | ||
clickAt | xpath=id('gt_act')/div[1]/ul/li[1]/span | |
pause | 2000 | |
storeEval | ${m} + 1 | m |
endWhile |
- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
Re: how to store csscount/xpath count in a variable and increment it?
Wed Oct 30, 2013 8:00 pm
Hi,
Thank you so much for your reply.
I tried to execute the code which you provided.
I am getting the following error on executing the code
[error] Unexpected Exception: ReferenceError: presents is not defined. fileName -> chrome://flowcontrol/content/extensions/goto-sel-ide.js?1383058567164, lineNumber -> 129, columnNumber -> 0
Any help on this would be very helpful.
Thanks.
Thank you so much for your reply.
I tried to execute the code which you provided.
I am getting the following error on executing the code
[ltr]gotoIf[/ltr] | [ltr]present == ""[/ltr] | [ltr]endinnerloop[/ltr] |
Any help on this would be very helpful.
Thanks.
- kashyap_guruActive particpant
- Posts : 24
Join date : 2013-10-16
Age : 37
Location : India
Re: how to store csscount/xpath count in a variable and increment it?
Thu Oct 31, 2013 10:41 am
Please compare your running code with code i have given here. There would be some change.Statement you have shown is having "present" and error shows "presents". So please compare once.
- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
Re: how to store csscount/xpath count in a variable and increment it?
Wed Nov 06, 2013 8:21 pm
Sorry to bother.
In your code one place you used presents and this is the code
StoreElementPresent //ul//li[contains(.,"Staff${n}")] presents
gotoIf presents == "" endcase
And other place you used present and this is the code
2.StoreElementPresent xpath=id('timesheet')/ul[${x}]/li[${y}]/a present
Not sure what went wrong. When I execute the code it throws error as
[error] Unexpected Exception: ReferenceError: presents is not defined. fileName -> chrome://flowcontrol/content/extensions/goto-sel-ide.js?1383058567164, lineNumber -> 129, columnNumber -> 0
I am getting the above error while executing the following line:
gotoIf presents == "" endcase.
Can you explain how the above line of code works.
Thanks for your help.
In your code one place you used presents and this is the code
StoreElementPresent //ul//li[contains(.,"Staff${n}")] presents
gotoIf presents == "" endcase
And other place you used present and this is the code
2.StoreElementPresent xpath=id('timesheet')/ul[${x}]/li[${y}]/a present
Not sure what went wrong. When I execute the code it throws error as
[error] Unexpected Exception: ReferenceError: presents is not defined. fileName -> chrome://flowcontrol/content/extensions/goto-sel-ide.js?1383058567164, lineNumber -> 129, columnNumber -> 0
I am getting the above error while executing the following line:
gotoIf presents == "" endcase.
Can you explain how the above line of code works.
Thanks for your help.
- kashyap_guruActive particpant
- Posts : 24
Join date : 2013-10-16
Age : 37
Location : India
Re: how to store csscount/xpath count in a variable and increment it?
Sat Nov 09, 2013 11:31 am
May be that element is not loaded when that command is fired. Try WAITFORELEMENTPRESENT or PAUSE command. May that work.
- sathiyarengarajanActive particpant
- Posts : 20
Join date : 2013-08-08
Re: how to store csscount/xpath count in a variable and increment it?
Mon Feb 10, 2014 11:19 pm
Anyway, thanks for the help.
I couldnot execute the above case. But I found a solution to my problem. I stored the current date in a variable. I booked all the slots for the current date.Then I incremented the date value to book appointments for the next date. Using while loop I checked for the condition whether the date is less than or equal to 31. At the end of the loop, I incremented the date value. So I can book appointments for the entire month starting from the current date. |
- Read text in TXT and store in Variable
- count of text
- how to verify the condition using verifytext and store the value in to variable either true or false.
- How Xpaths works in Selenium and What is the difference between native Xpath and absolute xpath and relative xpath.
- pass string variable from database in to variable and then insert into 3rd party website using selenium and click search button.
Permissions in this forum:
You cannot reply to topics in this forum