使用 Selenium 3 Webdriver 单击图像映射中的特定项目
Click Specific Item In Image Map Using Selenium 3 Webdriver
我正在使用 Selenium 3.3.1 和 Java Webdriver 绑定,需要单击页面图像映射中的特定项目。这是图像映射 HTML
<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 为 "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
driver.findElement(By.id("reports")).click();
driver.findElement(By.cssSelector("#reports")).click();
driver.findElement(By.xpath("//*[@id=\"reports\"]")).click();
以及其他 xpath 变体,例如 //area[@id='reports'].
我主要使用 Firefox 和 Geckodriver 0.15.0,但它也在其他浏览器中发生。有一个针对此 back in 2011 的 bug,但它被确定为仅 chrome,现在那个线程太旧了,它基本上没用了。如果有人最近做过这件事,如果他们能分享他们是如何做到的,那将会非常有帮助。谢谢!
回答我自己的问题,因为答案来自评论中的建议。使用 javascript 执行器就是答案。类似于:
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.3.1 和 Java Webdriver 绑定,需要单击页面图像映射中的特定项目。这是图像映射 HTML
<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 为 "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
driver.findElement(By.id("reports")).click();
driver.findElement(By.cssSelector("#reports")).click();
driver.findElement(By.xpath("//*[@id=\"reports\"]")).click();
以及其他 xpath 变体,例如 //area[@id='reports'].
我主要使用 Firefox 和 Geckodriver 0.15.0,但它也在其他浏览器中发生。有一个针对此 back in 2011 的 bug,但它被确定为仅 chrome,现在那个线程太旧了,它基本上没用了。如果有人最近做过这件事,如果他们能分享他们是如何做到的,那将会非常有帮助。谢谢!
回答我自己的问题,因为答案来自评论中的建议。使用 javascript 执行器就是答案。类似于:
WebElement banner = driver.findElement(By.cssSelector("map"));
WebElement area = banner.findElement(By.id("reports"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", area);