Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Help with easy script

View previous topic View next topic Go down

Help with easy script

Post by quake004 on Thu Jul 28, 2016 5:11 am

I want to buy the missing mtg cards from a deckbox collection in magiccardmarket, the logic is: move through the expansions, move through the pages of cards of the expansion and through the cards of each page. For each card copy it's name, go to the collection in a different window and search for the count of cards, if the count is 0 return to the base page and buy it.

This is the script so far:
Code:
open  |  https://www.magiccardmarket.eu/?mainPage=browseUserProducts&idCategory=1&idUser=13786&editMode=&cardName=&idExpansion=1668&idRarity=&idLanguage=4&condition_uneq=&condition=&isFoil=N&isSigned=N&isPlayset=N&isAltered=N&comments=&isWanted=&minPrice=&maxPrice=0.15
openWindow  |  https://deckbox.org/games/mtg/cards
selectWindow  |  null

<!--Login if needed-->
storeElementPresent  |  id=login-btn  |  login
gotoIf  |  ${login}==false  |  logged
type  |  id=username  |  quake004
type  |  id=userPassword  |  mypass
clickAndWait  |  id=login-btn
label  |  logged

<!--Loop pages-->
store  |  0  |  p
storeElementPresent  |  xpath=(//option[@value='${p}'])[3]  |  loopPages
while  |  ${loopPages}==true
storeEval  |  ${p}+1  |  p
gotoIf  |  ${p}==1  |  skip
selectAndWait  |  xpath=(//select[@name='selectResultsPage'])[2]  |  label=${p}
label  |  skip

<!--Loop the elements of a page-->
store  |  1  |  i
storeElementPresent  |  //div[@id='siteContents']/div[3]/div[2]/div/form/table/tbody/tr[${i}]  |  loopTable
while  |  ${loopTable}==true

<!--Copy card name-->
storeTable  |  //div[@id='siteContents']/div[3]/div[2]/div/form/table.${i}.2  |  card
<!--storeTable  |  //div[@id='siteContents']/div[3]/div[2]/div/form/table/tbody/tr[${i}]/td[3]  |  card

<!--Change tab to deckbox-->
selectWindow  |  Magic The Gathering full card listing - Deckbox

<!--Search card-->
type  |  id=filter_values_1  |  ${card}
clickAndWait  |  //button[@onclick='Tcg.filters.apply();return false;']

<!--If element present continue-->
storeElementPresent  |  link=${card}  |  present
gotoIf  |  ${present}==true  |  continue

<!--Else move to next page-->
clickAndWait  |  link=Next
label  |  continue

<!--Copy card count in collection-->
storeElementPresent  |  link=${card}  |  present
gotoIf  |  ${present}==true  |  continue2

<!--Copy the row that verifys the card name then copy the count for that row-->
<!--Missing command: copy row of card name-->
<!--storeTable  |  //div[@id='show_simple_contents']/div/table.{row}.1  |  count
storeTable  |  //div[@id='show_simple_contents']/div/table.2.1  |  count
label  |  continue2

<!--If card count is greater than 0 finish-->
gotoIf  |  ${count}>0  |  final

<!--If card count is equal to 0 change tab-->
selectWindow  |  null

<!--Put in shopping car-->
clickAndWait  |  css=#modifAmountLink233854915 > span.icon

label  |  final
storeEval  |  ${i}+1  |  i
<!--end loopTable-->
endWhile
storeElementPresent  |  xpath=(//option[@value='${p}'])[3]  |  loopPages
<!--end loopPages-->
endWhile

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://change-this-to-the-site-you-are-testing/" />
<title>ide</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">ide</td></tr>
</thead><tbody>
<tr>
   <td>open</td>
   <td>https://www.magiccardmarket.eu/?mainPage=browseUserProducts&idCategory=1&idUser=13786&editMode=&cardName=&idExpansion=1668&idRarity=&idLanguage=4&condition_uneq=&condition=&isFoil=N&isSigned=N&isPlayset=N&isAltered=N&comments=&isWanted=&minPrice=&maxPrice=0.15</td>
   <td></td>
</tr>
<tr>
   <td>openWindow</td>
   <td>https://deckbox.org/games/mtg/cards</td>
   <td></td>
</tr>
<tr>
   <td>selectWindow</td>
   <td>null</td>
   <td></td>
</tr>
<!--Login if needed-->
<tr>
   <td>storeElementPresent</td>
   <td>id=login-btn</td>
   <td>login</td>
</tr>
<tr>
   <td>gotoIf</td>
   <td>${login}==false</td>
   <td>logged</td>
</tr>
<tr>
   <td>type</td>
   <td>id=username</td>
   <td>quake004</td>
</tr>
<tr>
   <td>type</td>
   <td>id=userPassword</td>
   <td>mypass</td>
</tr>
<tr>
   <td>clickAndWait</td>
   <td>id=login-btn</td>
   <td></td>
</tr>
<tr>
   <td>label</td>
   <td>logged</td>
   <td></td>
</tr>
<!--Loop pages-->
<tr>
   <td>store</td>
   <td>0</td>
   <td>p</td>
</tr>
<tr>
   <td>storeElementPresent</td>
   <td>xpath=(//option[@value='${p}'])[3]</td>
   <td>loopPages</td>
</tr>
<tr>
   <td>while</td>
   <td>${loopPages}==true</td>
   <td></td>
</tr>
<tr>
   <td>storeEval</td>
   <td>${p}+1</td>
   <td>p</td>
</tr>
<tr>
   <td>gotoIf</td>
   <td>${p}==1</td>
   <td>skip</td>
</tr>
<tr>
   <td>selectAndWait</td>
   <td>xpath=(//select[@name='selectResultsPage'])[2]</td>
   <td>label=${p}</td>
</tr>
<tr>
   <td>label</td>
   <td>skip</td>
   <td></td>
</tr>
<!--Loop the elements of a page-->
<tr>
   <td>store</td>
   <td>1</td>
   <td>i</td>
</tr>
<tr>
   <td>storeElementPresent</td>
   <td>//div[@id='siteContents']/div[3]/div[2]/div/form/table/tbody/tr[${i}]</td>
   <td>loopTable</td>
</tr>
<tr>
   <td>while</td>
   <td>${loopTable}==true</td>
   <td></td>
</tr>
<!--Copy card name-->
<tr>
   <td>storeTable</td>
   <td>//div[@id='siteContents']/div[3]/div[2]/div/form/table/tbody/tr[${i}]/td[3]</td>
   <td>card</td>
</tr>
<!--Change tab to deckbox-->
<tr>
   <td>selectWindow</td>
   <td>Magic The Gathering full card listing - Deckbox</td>
   <td></td>
</tr>
<!--Search card-->
<tr>
   <td>type</td>
   <td>id=filter_values_1</td>
   <td>${card}</td>
</tr>
<tr>
   <td>clickAndWait</td>
   <td>//button[@onclick='Tcg.filters.apply();return false;']</td>
   <td></td>
</tr>
<!--If element present continue-->
<tr>
   <td>storeElementPresent</td>
   <td>link=${card}</td>
   <td>present</td>
</tr>
<tr>
   <td>gotoIf</td>
   <td>${present}==true</td>
   <td>continue</td>
</tr>
<!--Else move to next page-->
<tr>
   <td>clickAndWait</td>
   <td>link=Next</td>
   <td></td>
</tr>
<tr>
   <td>label</td>
   <td>continue</td>
   <td></td>
</tr>
<!--Copy card count in collection-->
<tr>
   <td>storeElementPresent</td>
   <td>link=${card}</td>
   <td>present</td>
</tr>
<tr>
   <td>gotoIf</td>
   <td>${present}==false</td>
   <td>continue2</td>
</tr>
<!--Copy the row that verifys the card name then copy the count for that row-->
<!--Missing command: copy row of card name-->
<tr>
   <td>storeTable</td>
   <td>//div[@id='show_simple_contents']/div/table.2.1</td>
   <td>count</td>
</tr>
<tr>
   <td>label</td>
   <td>continue2</td>
   <td></td>
</tr>
<!--If card count is greater than 0 finish-->
<tr>
   <td>gotoIf</td>
   <td>${count} > 0</td>
   <td>final</td>
</tr>
<!--If card count is equal to 0 change tab-->
<tr>
   <td>selectWindow</td>
   <td>null</td>
   <td></td>
</tr>
<!--Put in shopping car-->
<tr>
   <td>clickAndWait</td>
   <td>css=#modifAmountLink233854915 > span.icon</td>
   <td></td>
</tr>
<tr>
   <td>label</td>
   <td>final</td>
   <td></td>
</tr>
<tr>
   <td>storeEval</td>
   <td>${i}+1</td>
   <td>i</td>
</tr>
<!--end loopTable-->
<tr>
   <td>endWhile</td>
   <td></td>
   <td></td>
</tr>
<tr>
   <td>storeElementPresent</td>
   <td>xpath=(//option[@value='${p}'])[3]</td>
   <td>loopPages</td>
</tr>
<!--end loopPages-->
<tr>
   <td>endWhile</td>
   <td></td>
   <td></td>
</tr>
</tbody></table>
</body>
</html>


Last edited by quake004 on Thu Jul 28, 2016 9:10 pm; edited 4 times in total

quake004

Posts : 5
Join date : 2015-03-24

Back to top Go down

Re: Help with easy script

Post by quake004 on Thu Jul 28, 2016 9:06 pm

The script is failing right now at:
Code:
storeTable | //div[@id='siteContents']/div[3]/div[2]/div/form/table.${i}.2 | card
it has to copy the name of the card in the ${i} column into the variable card. It works in the first lap through the loop but it fails in the second. The problem is that the path varies between
Code:
//div[@id='siteContents']/div[3]/div[2]
//div[@id='siteContents']/div[4]/div[2]

Code:
<!--Copy card name-->
<tr>
 <td>storeTable</td>
 <td>//div[@id='siteContents']/div[3]/div[2]/div/form/table.${i}.2</td>
 <td>card</td>
</tr>


I want to change this part with a while that changes to next page while the element isn't found and while there are more pages.

Code:
<!--If element present continue-->
storeElementPresent  |  link=${card}  |  present
gotoIf  |  ${present}==true  |  continue

<!--Else move to next page-->
clickAndWait  |  link=Next
label  |  continue

<!--Copy card count in collection-->
storeElementPresent  |  link=${card}  |  present
gotoIf  |  ${present}==true  |  continue2

<!--Copy the row that verifys the card name then copy the count for that row-->
<!--Missing command: copy row of card name-->
<!--storeTable  |  //div[@id='show_simple_contents']/div/table.{row}.1  |  count
storeTable  |  //div[@id='show_simple_contents']/div/table.2.1  |  count
label  |  continue2

Code:
<!--If element present continue-->
<tr>
 <td>storeElementPresent</td>
 <td>link=${card}</td>
 <td>present</td>
</tr>
<tr>
 <td>gotoIf</td>
 <td>${present}==true</td>
 <td>continue</td>
</tr>
<!--Else move to next page-->
<tr>
 <td>clickAndWait</td>
 <td>link=Next</td>
 <td></td>
</tr>
<tr>
 <td>label</td>
 <td>continue</td>
 <td></td>
</tr>
<!--Copy card count in collection-->
<tr>
 <td>storeElementPresent</td>
 <td>link=${card}</td>
 <td>present</td>
</tr>
<tr>
 <td>gotoIf</td>
 <td>${present}==false</td>
 <td>continue2</td>
</tr>

quake004

Posts : 5
Join date : 2015-03-24

Back to top Go down

Re: Help with easy script

Post by quake004 on Thu Jul 28, 2016 9:55 pm

I changed the shopping link with
Code:
//table[@class="MKMTable specimenTable MKMSortable"].${i}/[id^='modifAmountLink']/span[2]
//table[@class="MKMTable specimenTable MKMSortable"]/tbody/tr[${i}]/a[id^='modif']/span[2]
//*[@id='siteContents']/div[3]/div[2]/div/form/table/tbody/tr[2]/td[16]/div/span[2]
//table[@class="MKMTable specimenTable MKMSortable"]/tbody/tr[${i}]/td[16]/div/span[2]

this helped me https://saucelabs.com/selenium/css-selectors
It's not correct though.

Code:
storeTable  |  //table[@class="MKMTable specimenTable MKMSortable"]/tbody/tr[${i}]/td[2]  |  card
gives:

Code:
[error] Invalid target format. Correct format is tableName.rowNum.columnNum

so use:

Code:
//table[@class="MKMTable specimenTable MKMSortable"].${i}.2





http://stackoverflow.com/questions/11131836/how-to-increase-decrease-the-sleep-time-in-clickandwait-command-in-selenium-ide

quake004

Posts : 5
Join date : 2015-03-24

Back to top Go down

Re: Help with easy script

Post by Sponsored content Today at 5:03 am


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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