mardi 23 février 2016

splinter drop-down selection blocks web interaction

I am trying write a script in order to automate some web interaction. I'd like my script to select the last option from a drop-down menu and then click the cart button for a check-out.

The website I'd like to interact with has the following code:

<tr class="lastDiscountLevelRow">

<td class="single-rowspan discountLevel">No discount</td>
<td class="single-rowspan price" nowrap="nowrap">
<div>
USD ($)
<strong>12,09</strong>
</div>
</td>
<td class="single-rowspan tixxSelect" colspan="2">
<select name="rs_menge_31163917" id="DetailItems" size="1" class="pricedItems">
<option value="0"/>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</td>
<td class="shoppingCartBtn" style="width: 160px;">
<div class="shoppingCartEl floatRight" style="position: static;">
<span class="defSubmit shoppingCartSubmit floatLeft">
<input type="submit" id="Detail_1" name="toShoppingCart" class="submit" value="check out"/>
</span>
</div>
</td>
</tr>

My splinter code is

from splinter import Browser
browser = Browser('chrome')

#Link webpage:
browser.visit('http://ift.tt/1ozyGJi')    

browser.find_by_xpath('//select/option[last()]').click()

browser.find_by_xpath('//td[@class="shoppingCartBtn"]').click()

For some reason it does select the last item from the drop-down menu choice, but it doesn't click the shopping cart button for checkout. If I comment out the selection line

#browser.find_by_xpath('//select/option[last()]').click()

then it does click on the checkout chart (I get an error message saying "you should select the item from the drop-down list before you can check out").

Is it anything to do with javascript or jquery? I'm confused.

Please help and sorry if that's not too clear but I am new to splinter coding.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire