与此question相关的案例。喜欢它,我尝试点击其中一个区域。我尝试使用python和splinter实现它。我不擅长它需要你的帮助。
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="expires" content="0">
<meta name="robots" content="noindex">
<title>CS121 SNMP/Web Adapter</title>
<script type="text/javascript" src="/lang/lang.json"></script>
<script type="text/javascript" src="/js/gxlang.js"></script>
</head>
<frameset cols="216,*" frameborder="0" framespacing="0" border="0">
<frame src="menu.shtml" name="cs_menu" frameborder="0">
<frameset rows="73,*" frameborder="0" framespacing="0" border="0">
<frame src="status.shtml" name="cs_status" frameborder="0" scrolling="no">
<frame src="default.shtml" name="cs_main" frameborder="0">
</frameset>
</frameset>
现在我指向default.shtml
<body class="main">
<h2><script type="text/javascript">_dw("Loading")</script> <a href="/main.shtml">/main.shtml</a> ...</h2>
</body>
</html>
在main.shtml旁边
<body class="main">
<img src="load.gif" width="36" height="36" name="ajax" id="ajax" style="position:absolute; left:10px; top:10px; z-index:5; border:0; display:none; filter:Alpha(opacity=80, finishopacity=20, style=2);">
<img src="led1.gif" width="16" height="16" name="led1" style="position:absolute; left:98px; top:212px; z-index:3; border:0;">
<img src="led1.gif" width="16" height="16" name="led2" style="position:absolute; left:320px; top:205px; z-index:3; border:0;">
<img src="led1.gif" width="16" height="16" name="led3" style="position:absolute; left:474px; top:205px; z-index:3; border:0;">
<img src="led1.gif" width="16" height="16" name="led4" style="position:absolute; left:573px; top:212px; z-index:3; border:0;">
<img src="led1.gif" width="16" height="16" name="led5" style="position:absolute; left:334px; top:410px; z-index:3; border:0;">
<img src="led1.gif" width="16" height="16" name="led6" style="position:absolute; left:398px; top:266px; z-index:3; border:0;">
<img src="b.png" style="position:absolute; top:8px; left:8px; z-index:1; border:0;" usemap="#cetmap">
<map name="cetmap">
<area shape="rect" coords="300,184,496,314" href="main2.shtml" alt="Show Modules" title="Show Modules">
**<area shape="rect" coords="79,195,239,302" href="#" onclick="return toggle_infobox('ac_groups')" alt="Show AC Groups" title="Show AC Groups">**
<area shape="rect" coords="260,226,280,246" href="#" onclick="return toggle_infobox('ac_groups2')" alt="Show AC Groups Transfer Parameters" title="Show AC Groups Transfer Parameters">
<area shape="rect" coords="314,394,478,499" href="#" onclick="return toggle_infobox('dc_groups')" alt="Show DC Groups" title="Show DC Groups">
<area shape="rect" coords="400,344,420,364" href="#" onclick="return toggle_infobox('dc_groups2')" alt="Show DC Groups Transfer Parameters" title="Show DC Groups Transfer Parameters">
<area shape="rect" coords="553,195,718,302" href="#" onclick="return toggle_infobox('phases')" alt="Show Phases" title="Show Phases">
<area shape="rect" coords="514,226,534,246" href="#" onclick="return toggle_infobox('phases2')" alt="Show Phases Transfer Parameters" title="Show Phases Transfer Parameters">
</map>
我尝试点击“**”区域
我尝试了几件事。这就是我现在所拥有的:
#!/usr/bin/env python
from splinter import Browser
from time import sleep
from lxml import html
from random import randrange
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
exitCode = 0
def my_range(start, end, step):
while start <= end:
yield start
start += step
with Browser('firefox', headless=True) as browser:
browser.visit("http://1.1.1.1")
sleep(22)
browser.driver.save_screenshot('ups2.png')
test = browser.find_by_name("cetmap")
test2 = browser.driver.find_elements_by_cssSelector("body > map:nth-child(9) > area:nth-child(3)")
browser.execute_script("arguments[0].click();", test2)
sleep(5)
browser.driver.save_screenshot('ups.png')
browser.quit()
exit(0)
答案 0 :(得分:0)
所以,我处理这个问题。所以也许有人会搜索类似问题的解决方案。经过一番检查,我的同事弄清楚这张地图是三帧之一。当我将脚本集中在这个特定的框架时,我可以“创建”我的解决方案。这是解决这个问题的方法:
在分裂时,我们得到了broswer.execution_sctipt,我们很容易实现:
b = Broswer('firefox')
b.visit("http://1.1.1.1/main.shtml") #this is addres of my frame
#run script from onclick option
b.execute_script("return toggle_infobox(\'ac_groups2\')")
这是解决方案。