问题描述:

I am trying to run a splinter script in order to find a menu option in this webpage.

The menu's HTML looks like this:

<table border="0" cellpadding="0" cellspacing="0" width="100%" class="logo">

<tbody><tr>

<td align="left" style="background : url('gfx/tab_fill.png'); background-repeat : repeat-x;">

...

<a href="variants">

<img src="gfx/tab_variants_F.png" alt="View variants" id="tab_variants" width="58" height="25" align="left" class="">

</a>

...

</td>

</tr>

</tbody></table>

<ul id="menu_tab_variants" class="jeegoocontext" style="display: none; left: 180px; top: 90px;">

<li class="icon"><a href="/variants" class="">

<span class="icon" style="background-image: url(gfx/menu_magnifying_glass.png);"></span>View all genomic variants</a></li>

<li class="icon"><a href="/variants/in_gene" class="">

<span class="icon" style="background-image: url(gfx/menu_magnifying_glass.png);"></span>View all variants affecting transcripts</a></li>

<li class="icon"><a href="/submit" class="">

<span class="icon" style="background-image: url(gfx/plus.png);"></span>Create a new data submission</a></li>

...

</ul>

The script should hover over a menu header, show what is visible, and then hover out of it and show what elements are visible. But nothing appears visible.

from splinter import Browser

browser = Browser('firefox', wait_time=10)

browser.visit("http://databases.lovd.nl/shared/variants")

tab_variants = browser.find_link_by_href("variants")

print tab_variants

tab_variants.first.mouse_over()

print browser.find_link_by_partial_text(

"View all genomic variants").first.visible

print browser.find_link_by_partial_text(

"View all variants affecting transcripts").first.visible

tab_variants.mouse_out()

print browser.find_link_by_partial_text(

"View all genomic variants").first.visible

print browser.find_link_by_partial_text(

"View all variants affecting transcripts").first.visible

I get this output:

[<splinter.driver.webdriver.WebDriverElement object at 0x18c29d0>]

False

False

False

False

Am I using the mouse_over method as it is intended in splinter or is there something about this particular menu that splinter can't deal with.

网友答案:

The menu is not yet visible at the time you are checking the .visible property. You can however wait for it by moving the mouse to the sub menu:

from splinter import Browser

browser = Browser('firefox', wait_time=10)
browser.visit("http://databases.lovd.nl/shared/variants")

# move over the menu "Variant"
browser.find_by_id('tab_variants').mouse_over()
# move over the sub menu
browser.find_by_id('menu_tab_variants').mouse_over()

# print the menu items visibility
print browser.find_link_by_text("View all genomic variants").visible
print browser.find_link_by_text("View all variants affecting transcripts").visible

# move the mouse out of the sub menu
browser.find_by_id('menu_tab_variants').mouse_out()

# print the menu items visibility
print browser.find_link_by_text("View all genomic variants").visible
print browser.find_link_by_text("View all variants affecting transcripts").visible
相关阅读:
Top