我无法点击图片中显示的链接 - >地图 - >区域标签。任何人都可以帮我解决这个问题。我想点击否(或)关闭。
<div id="IPEinvL" style="z-index: 10000; width: 439px; height: 360px; left: 463px; top: 0px; background-color: white; position: absolute; margin-left: 0px; margin-top: 0px;">
<img alt="Would you like to participate in a short study?" usemap="#IPEMap" src="XXXXXXXXXXXXXXXXXXXX.png" border="0" height="360" width="439">
<map name="IPEMap">
<area shape="rect" coords="405,15,424,33" href="javascript:clWin()" alt="close">
<area shape="rect" coords="117,229,214,258" href="javascript:fOpen()" alt="yes">
<area shape="rect" coords="225,229,323,258" href="javascript:clWin()" alt="no">
</map>
<img id="countInvites" src="XXXXXXXXXXXXXXXXX/Counter/counter_N.png?surveyID=120799&siteID=1&langID=1&traceID=2" style="border: 0px; margin-top: -10px;" alt="" height="0" width="0">
</div>
答案 0 :(得分:0)
以下代码可能有效。
方法1:
WebElement close=driver.findElement(By.xpath("//*[@id='IPEinvL']/map/area[@alt='close']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();",close);
方法2:
WebElement close=driver.findElement(By.xpath("//*[@id='IPEinvL']/map/area[@alt='close']"));
String hrefvalue=close.getAttribute("href");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(hrefvalue);
方法3: 使用Actions类
new Actions(driver).click(close).build().perform();
答案 1 :(得分:0)
Java click()
必须如下工作:
点击No
:
driver.findElement(By.xpath("//map[@name='IPEMap']/area[@alt='no']")).click();
点击Close
:
driver.findElement(By.xpath("//map[@name='IPEMap']/area[@alt='close']")).click();