从列表框中选择项目

时间:2014-11-21 21:18:17

标签: python selenium

我尝试在列表框中选择一个元素。并非所有元素都可见。我使用的代码工作直到第9个孩子罚款。使用chrome找到的xpath找不到任何更高的元素。 通过发送向下箭头键使元素可见无济于事。

Element_not_found = True
loop = 0
while Element_not_found:
    try:
        time.sleep(1)
        loop = loop +1
        print "We gaan kijken of het element er al is"
        element = driver.find_element_by_xpath('//*[@id="syi-categories-l1"]/ul/li[9]')
        driver.find_element_by_xpath('//*[@id="syi-categories-l1"]/ul/li[9]').click()
        print "Element is er"
        Element_not_found = False
    except:
        print "We gaan op het pijltje drukken", Element_not_found
        driver.find_element_by_xpath('//*[@id="syi-categories-l1"]/ul').send_keys(Keys.ARROW_DOWN)
        if loop == 10:
            Element_not_found = False 
time.sleep(3)

HTML代码:     Handmatig uw rubriek kiezen     
                 Kies groep

<ul class="listbox item-frame" tabindex="0">
<li class="item " data-val="1" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1_antiek-en-kunst">Antiek en Kunst</li>
<li class="item " data-val="31" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/31_audio-tv-en-foto">Audio, Tv en Foto</li>
<li class="item " data-val="91" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/91_auto-s">Auto's</li><li class="item " data-val="2600" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/2600_auto-onderdelen">Auto-onderdelen</li>
<li class="item " data-val="48" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/48_auto-diversen">Auto diversen</li>
<li class="item " data-val="201" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/201_boeken">Boeken</li>
<li class="item " data-val="289" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/289_caravans-en-kamperen">Caravans en Kamperen</li>
<li class="item " data-val="1744" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1744_cd-s-en-dvd-s">Cd's en Dvd's</li>
<li class="item " data-val="322" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/322_computers-en-software">Computers en Software</li>
<li class="item " data-val="378" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/378_contacten-en-berichten">Contacten en Berichten</li>
<li class="item " data-val="1098" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1098_diensten-en-vakmensen">Diensten en Vakmensen</li>
<li class="item " data-val="395" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/395_dieren-en-toebehoren">Dieren en Toebehoren</li>
<li class="item " data-val="239" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/239_doe-het-zelf-en-verbouw">Doe-het-zelf en Verbouw</li>
<li class="item " data-val="445" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/445_fietsen-en-brommers">Fietsen en Brommers</li>
<li class="item " data-val="1099" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1099_hobby-en-vrije-tijd">Hobby en Vrije tijd</li>
<li class="item " data-val="504" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/504_huis-en-inrichting">Huis en Inrichting</li>
<li class="item " data-val="1032" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1032_huizen-en-kamers">Huizen en Kamers</li>
<li class="item " data-val="565" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/565_kinderen-en-baby-s">Kinderen en Baby's</li>
<li class="item " data-val="621" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/621_kleding-dames">Kleding | Dames</li>
<li class="item " data-val="1776" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1776_kleding-heren">Kleding | Heren</li>
<li class="item " data-val="678" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/678_motoren">Motoren</li>
<li class="item " data-val="728" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/728_muziek-en-instrumenten">Muziek en Instrumenten</li>
<li class="item " data-val="1784" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1784_postzegels-en-munten">Postzegels en Munten</li>
<li class="item " data-val="1826" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1826_sieraden-tassen-en-uiterlijk">Sieraden, Tassen en Uiterlijk</li>
<li class="item " data-val="356" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/356_spelcomputers-en-games">Spelcomputers en Games</li>
<li class="item " data-val="784" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/784_sport-en-fitness">Sport en Fitness</li>
<li class="item " data-val="820" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/820_telecommunicatie">Telecommunicatie</li>
<li class="item " data-val="1984" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1984_tickets-en-kaartjes">Tickets en Kaartjes</li>
<li class="item " data-val="1847" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1847_tuin-en-terras">Tuin en Terras</li>
<li class="item " data-val="167" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/167_vacatures">Vacatures</li>
<li class="item " data-val="856" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/856_vakantie">Vakantie</li>
<li class="item " data-val="895" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/895_verzamelen">Verzamelen</li>
<li class="item " data-val="976" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/976_watersport-en-boten">Watersport en Boten</li>
<li class="item " data-val="537" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/537_witgoed-en-apparatuur">Witgoed en Apparatuur</li>
<li class="item " data-val="1085" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/1085_zakelijke-goederen">Zakelijke goederen</li>
<li class="item " data-val="428" data-ga-track-page-view-on-click="/SYI/SELECTCATEGORY/428_diversen">Diversen</li></ul>
<input type="hidden" name="l1" value="-1">

0 个答案:

没有答案