2017-04-03 98 views
-1
<button class="close" type="button" data-dismiss="modal" aria-label="Close"> 
<img src="/images/ic_highlight_removegray.svg" alt=""> 
</button> 

我試過點擊這個彈出(X)圖像,這是鏈接。我已經完成了所有可能的選擇器,包括Xpath,類& cssSelectors但沒有結果。請建議這是一個特殊的圖像/按鈕的情況。點擊圖片作爲按鈕?

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
Thread.sleep(35000); 
driver.findElement(By.xpath(".//*[@id='share_preview_modal']/div/div[1]/button")).click(); 

我還試圖用相同的等待,相對&絕對的xpath,.sendKeys(Keys.ENTER); - 失敗

<div id="share_preview_modal" class="modal fade pro_info_member in dashboard-modal" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="user_profile" style="display: block;"> 
<div class="modal-dialog " role="document"> 
<div class="modal-header"> 
<div class="preview-header"> 
<span class="success-msg white_box_info" style="display:none">Restricted email access to domains </span> 
<button class="close" type="button" data-dismiss="modal" aria-label="Close"> 
<img src="http://some-url/images/ic_highlight_removegray.svg" alt=""> 
</button> 
</div> 
<div class="modal-content white-popup " style="background-image: url("");"> 
<!-- white popoup --> 
</div> 
</div> 
+0

嘗試以下XPath://'IMG [@src = '/圖片/ ic_highlight_removegray.svg']'' –

+0

//按鈕[@類= 'close'] [@ data-dismiss ='modal'] [@ aria-label ='關閉']' –

+0

感謝您對'Kishan'的快速響應,但共享xpath也無法正常工作。 –

回答

0

你可以試試這個XPath點擊關閉按鈕:

driver.findElement(By.xpath("//div[id='share_preview_modal']//button[@class='close']")).click();

driver.findElement(By.xpath("//div[@id='share_preview_modal']//button[@class='close']")).click();

driver.findElement(By.xpath("//div[*id='share_preview_modal']//button[@class='close']")).click();

讓我知道這是否對你有幫助。

+0

同樣的xPath我在開始時從螢火蟲那裏得到了,但這也沒有奏效。 –

+0

@AshishKumar能否讓我更多地瞭解相關的HTML DOM? – DebanjanB

+0

您的xpath在這裏不起作用,您沒有正確關閉雙引號。 '(「// button [@ class ='close']」)' –

-1

隨着硒3,方法「點擊」有一些問題。如果此方法不起作用,你可以試試:

driver.findElement(By.xpath("//div[*id='share_preview_modal']//button[@class='close']")).sendKeys(Keys.RETURN); 
+1

OP提及他已經嘗試過'sendKeys(Keys.ENTER)' – Andersson

+0

同意@Andersson – CodeMonkey