2017-04-03 97 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