Selenium webdriver 点击图像作为按钮?

Selenium webdriver 点击图像作为按钮?,selenium-webdriver,Selenium Webdriver,我还尝试了wait、relative和absolutexpath、.sendKeys(Keys.ENTER);-失败 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); Thread.sleep(35000); driver.findElement(By.xpath(".//*[@id='share_preview_modal']/div/div[1]/button")).click(); 限制对域的电子邮件访问

我还尝试了wait、relative和absolutexpath、.sendKeys(Keys.ENTER);-失败

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

限制对域的电子邮件访问

您可以尝试使用此xpath来单击关闭按钮:

driver.findElement(By.xpath(//div[id='share\u preview\u modal']//按钮[@class='close'])。单击()

driver.findElement(By.xpath(//div[@id='share\u preview\u modal']//按钮[@class='close'])。单击()

driver.findElement(By.xpath(//div[*id='share\u preview\u modal']//按钮[@class='close'])。单击()

如果这对您有帮助,请告诉我。

对于Selenium 3,方法“单击”有一些问题。如果此方法不起作用,您可以尝试:

    <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>

尝试以下xpath:
//img[@src='/images/ic_highlight_removegray.svg']
//按钮[@class='close'][@data dismission='modal'][@aria label='close']
感谢您的快速响应'Kishan',但共享xpath也无法工作。您遇到了什么错误?请分享一个检查关闭按钮的屏幕截图,你能分享你在尝试单击时遇到的错误吗?与我从firebug开始时得到的xPath相同,但这也不起作用。@AshishKumar,你能给我一些相关HTML DOM吗?你的xPath在这里不起作用,你没有正确关闭双引号<代码>(“//button[@class='close'])
Right'Jainish'先生,我也用正确的语法进行了尝试。@AshishKumar您能用更新的答案尝试一下并更新我吗。Thank.OP提到他已经尝试了
sendKeys(Keys.ENTER)
Agree@Andersson
    <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>
driver.findElement(By.xpath("//div[*id='share_preview_modal']//button[@class='close']")).sendKeys(Keys.RETURN);