0

I created a little test of selenium in order to buy a pair of shoes in various sites in the exact moment when they are released, I would like that my test was able to refresh over and over the page until the shoes becomes available, so that I should not keep to the pc to start all the tests. this is possible?

Thanks in advance

This is my code :

<tr>
<td>open</td>
<td> LINK SHOE</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=div.opt-sel</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[@id='content']/div[3]/div[2]/div[2]/div/div[2]/div[2]/div/ul/li[6]/div/</td>
<td></td>
</tr>
</tbody></table>
</body> 
</html>

2 Answers2

1

The idea is to put similar piece of code to use :

// your first condition of opening a page of shoe
while("add to chart is not available") {
  driver.refresh(); //this would keep on refreshing unconditionally unless your item is found
  wait(2000); // would suggest adding some wait()
}
// once add to chart is available, it would come out of the loop
// execute further your 2nd and 3rd command
Naman
  • 27,789
  • 26
  • 218
  • 353
  • sorry but I have not understand where i should to put the code. In particoular: the first command open the page of the shoe and the others two commands have the task of add to chart and proceed to checkout. (very simple) But if the shoe is not avaiable the 2nd and 3 command don't work naturally. in this case i need to refresh the page over and over again and when the product is avaiable, the others two command will have to work and buy automatically Thanks in advance – Edoardo May 30 '16 at 16:01
  • @Edoardo : answer modified – Naman May 30 '16 at 16:10
  • like this? open while (;add to chart is not available;) driver.refresh() wait 2000 click css=div.opt-sel click //div[@id='content']/div[3]/div[2]/div[2]/div/div[2]/div[2]/div/ul/li[6]/div/ endWhile – Edoardo May 30 '16 at 17:56
1

It is possible. You can achieve this by using the storeElementPresent command to detect whether a page element is already present or not. It returns boolean values (true/false) which can be used in a conditional expression for gotoIf command. See example below...


Command: storeElementPresent

Target: <locator-for-shoes>

Value: shoes


Command: gotoIf

Target: ${shoes}==false

Value: RefreshPage


Command: label

Target: RefreshPage

Value:


Command: refreshAndWait

Target:

Value:


Command: gotoIf

Target: ${shoes}==false

Value: RefreshPage

Rodel Bernal
  • 323
  • 2
  • 13