简体   繁体   English

如何在Java中使用Selenium在模态窗口中单击“确定”按钮?

[英]How can I click an OK button in a modal window using selenium with java?

I am trying to automate a script for a website I am currently working on. 我正在尝试为当前正在工作的网站自动化脚本。

I tried using xpath and cssSelector but it's not finding the button. 我尝试使用xpathcssSelector但找不到按钮。 I have a class name but it's with spaces. 我有一个班级名称,但带有空格。

HTML code for the button: 按钮的HTML代码:

按钮的HTML代码

I have used Thread.Sleep(3000) . 我已经使用Thread.Sleep(3000) Here is the cssSelector code for it: 这是它的cssSelector代码:

 driver.findElement(By.cssSelector("#ui_modal_1505889041536 > div.actions > div.ui.approve.positive.button")).click();

And here is the xpath : 这是xpath

driver.findElement(By.xpath("//*[@id=\"ui_modal_1505889041536\"]/div[3]/div[2]")).click();

The error I am receiving when using the cssSelector: 使用cssSelector时收到的错误:

在此处输入图片说明

我建议您使用以下xpath:

driver.findElement(By.xpath("//*[@id='ui_modal_1505889041536']//*[text()='ok']").click();

I have found this answer: 我找到了这个答案:

driver.findElement(By.xpath("//div[@class='ui approve positive button']")).click();

This works ! 这有效! Thanks for all your help guys! 感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM