如何使用selenium和java在模态窗口中单击“确定”按钮?

时间:2017-09-20 06:36:29

标签: java selenium css-selectors selenium-chromedriver

我正在尝试为我目前正在处理的网站自动化脚本。

我尝试使用xpathcssSelector,但未找到该按钮。我有一个班级名称,但它有空格。

按钮的HTML代码:

HTML code for the button

我使用过Thread.Sleep(3000)。 以下是cssSelector代码:

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

这是xpath

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

使用cssSelector时收到的错误:

enter image description here

2 个答案:

答案 0 :(得分:0)

我建议您使用以下xpath:

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

答案 1 :(得分:0)

我找到了这个答案:

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

这个有效!谢谢你们的帮助!