单击使用Selenium 3 Webdriver的图像映射中的特定项目 [英] Click Specific Item In Image Map Using Selenium 3 Webdriver

查看:108
本文介绍了单击使用Selenium 3 Webdriver的图像映射中的特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium 3.3.1和Java Webdriver绑定,并且需要单击页面上图像映射中的特定项.这是图片地图的HTML

I am using Selenium 3.3.1 and the Java Webdriver bindings, and need to click a specific item in an image map on a page. Here is the HTML for the image map

<img id="menu1" name="menu1" src="../../images/images/menu23t.gif" width="950" height="68" border="0" usemap="#Map">

<map name="Map">
    <area id="manager_indx" shape="rect" coords="220,13,297,60" href="../../backend/manager/index.php" target="_parent">
    <area id="pos" shape="rect" coords="306,13,336,60" href="http://10.10.10.99:8080/frontend/index.html" target="_parent">
    <area id="end_of_day" shape="rect" coords="347,13,410,60" href="../../backend/manager/end_of_day.php" target="_parent">
    <area id="customer" shape="rect" coords="415,10,470,60" href="../../backend/managecustomers/index.php" target="_parent">
    <area id="employee" shape="rect" coords="477,12,537,60" href="../../backend/employee_f/index.php" target="_parent">
    <area id="reports" shape="rect" coords="540,12,590,61" href="#" onclick="chk_report_security()">
    <area id="cash" shape="rect" coords="596,13,640,60" href="../../backend/manage_register/index.php" target="_parent">
    <area id="inventory" shape="rect" coords="650,12,705,60" href="../../backend/inventory/index.php" target="_parent">
    <area id="configuration" shape="rect" coords="720,11,802,60" href="../../backend/generalsetup/configuration.php" target="_parent">
    <area id="logon" shape="rect" coords="815,11,848,60" href="http://10.10.10.99:8080/frontend/index.html" target="_parent">
    <area id="exit" shape="rect" coords="852,11,890,61" href="javascript:javascript:exit_logout();">
    <area id="help" shape="rect" coords="892,14,937,60" href="javascript:top.banner.openContainer(window.parent.banner.isThrive);" target="_parent">
</map>

这是我尝试让其单击ID为报告"的区域的内容.

And here are the things I have tried to get it to click the area with the ID "reports".

WebElement banner = driver.findElement(By.cssSelector("map"));
WebElement area = banner.findElement(By.id("reports"));
area.click();//This click isn't working

我也尝试过使用ID,cssSelector和xpath

I have also tried by ID, cssSelector, and xpath

driver.findElement(By.id("reports")).click();

driver.findElement(By.cssSelector("#reports")).click();

driver.findElement(By.xpath("//*[@id=\"reports\"]")).click();

和其他xpath变体,例如//area [@ id ='reports'].

And other xpath variants like //area[@id='reports'].

我主要使用Firefox和Geckodriver 0.15.0,但是它也在其他浏览器中发生.早在2011年,此打开了一个错误 ,但这被确定为仅适用于chrome,而现在该线程已经很老了,基本上没有用.如果有人最近做过这件事,那么如果他们可以分享他们的做事方式将对您有极大的帮助.谢谢!

I'm primarily using Firefox and Geckodriver 0.15.0, but its happening in other browsers too. There was a bug opened for this back in 2011, but that was determined to be chrome only, and by now that thread so old its basically useless. If anyone has done this recently, it would help immensely if they could share how they did it. Thank you!

推荐答案

回答我自己的问题,因为答案来自评论中的建议.答案是使用JavaScript执行器.像这样:

Answering my own question because the answer came from a suggestion in the comments. Using a javascript executor was the answer. Something like:

WebElement banner = driver.findElement(By.cssSelector("map"));
WebElement area = banner.findElement(By.id("reports"));

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", area);

这篇关于单击使用Selenium 3 Webdriver的图像映射中的特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆