【发布时间】:2018-12-31 07:13:14
【问题描述】:
我正在使用 Python 开发 Selenium。我对此很陌生,我正在尝试单击具有以下 HTML 的图像
结构:
HTML:
<div id="result">
<img class="img-450" usemap="#476872907" src="#" border="0" title="Click on a repeated (mirrored) image bellow" alt="">
<map name="476872907">
<area class="cursor" onclick="javascript:Captcha107('6k9frpw1');" title="Click on a repeated (mirrored) image bellow" coords="1,4,63,88">
<area class="cursor" onclick="javascript:Captcha107('ya3ltbiv');" title="Click on a repeated (mirrored) image bellow" coords="65,4,128,88">
<area class="cursor" onclick="javascript:Captcha107('9rbukmey');" title="Click on a repeated (mirrored) image bellow" coords="129,4,191,88">
<area class="cursor" onclick="javascript:Captcha107('5mlv909r');" title="Click on a repeated (mirrored) image bellow" coords="192,4,255,88">
<area class="cursor" onclick="javascript:Captcha107('eu7idjnz');" title="Click on a repeated (mirrored) image bellow" coords="257,4,319,88">
<area class="cursor" onclick="javascript:Captcha107('al9a6zih');" title="Click on a repeated (mirrored) image bellow" coords="321,4,384,88">
<area class="cursor" onclick="javascript:Captcha107('nyvkjeoc');" title="Click on a repeated (mirrored) image bellow" coords="385,4,448,88">
</map>
</div>
我已经尝试了几件事,例如:
driver.find_element_by_xpath('//img/@class="img-450"').click()
driver.find_element_by_xpath('//area[@class="cursor"]').click()
但是,我似乎总是以错误告终,例如:
selenium.common.exceptions.WebDriverException: Message: unknown error: shape= is not supported
或
sselenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //img/@class="img-450" because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
我想知道是否可以使用区域元素以某种方式单击图像。
任何可以为我指明正确方向的想法都会很棒。谢谢。
【问题讨论】:
-
请分享相关的HTML时钟
-
添加了html代码
标签: selenium selenium-chromedriver