2017-09-14 69 views
0

我無法點擊圖像 - >地圖 - >區域標記中的鏈接。任何人都可以幫助我解決這個問題。我想單擊否(或)關閉。如何點擊使用硒的圖像上的鏈接java

<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&amp;siteID=1&amp;langID=1&amp;traceID=2" style="border: 0px; margin-top: -10px;" alt="" height="0" width="0"> 
</div> 

回答

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(); 
+0

我都試過3種方法得到下面的異常org.openqa.selenium.NoSuchElementException:找不到元素:// * [@ id ='IPEinvL']/img/map/area [@ alt ='close'] –

+0

抱歉xpath錯誤應該是// * [@ id ='IPEinvL']/map/area [@ ALT = '關閉'。請檢查更新的xpath – Murthi

+0

Xpath // * [@ id ='IPEinvL']/map/area [@ alt ='close']。爲我工作。它拯救了我的一天。謝謝! –

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(); 
    
+0

我試過兩個都不行。 –