简体   繁体   English

在硒中,无法单击错误消息“确定”按钮

[英]In selenium, Not able to click on Error msg 'OK' button

在此处输入图片说明

I'm trying to click on OK Button using selenium, cant find the elememt. 我正在尝试使用硒单击“确定”按钮,找不到elememt。

objBrowser.findElement(By.xpath("//button[contains(text(), 'OK')]")).click();

OK button Inspect element code as below 确定按钮检查元素代码如下

<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false" jQuery15109548211953493255="16">

<span class="ui-button-text"> Text - OK

text() only selects text child nodes under the current context node ( button ). text()仅选择当前上下文节点( button )下的文本子节点。 There is no text node that contains OK in button . button没有包含“确定”的文本节点。

You need most likely: 您最有可能需要:

By.xpath("//button[contains(span/text(), 'OK')]")

If the element is not immediately visible or clickable, you need to wait for it. 如果该元素不是立即可见或不可单击的,则需要等待它。 This is usually done with a WebdriverWait: 这通常通过WebdriverWait完成:

WebDriverWait wait = new WebDriverWait(webDriver, 3); // 3 seconds at most
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(...));

尝试使用cssSelector。

objBrowser.findElement(By.cssSelector("button:contains('Ok')")).click();

Include it in your test code 将其包含在您的测试代码中

import org.openqa.selenium.Alert;

and after the action which opens the alert message 在打开警报消息的操作之后

Try below code 试试下面的代码

Alert alert_test = driver.switchTo().alert();

alert_test.accept();

Let me know the error message in-case if it does not works. 如果无法正常工作,请告诉我错误消息。

For Modal pop-up window , Try below approach and verify. 对于模式弹出窗口 ,请尝试以下方法并进行验证。

Use below code after the action which opens the alert message 在打开警报消息的操作之后使用以下代码

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_TAB);

robot.keyRelease(KeyEvent.VK_TAB);

Note: Some-times it takes few seconds to recognize the modal pop-up window present but some times it goes a bit long,so below time you can modify as per your need. 注意: 有时需要几秒钟才能识别出当前的模式弹出窗口,但有时又要花一些时间,因此您可以根据需要修改以下时间。

Thread.sleep(7000);

robot.keyPress(KeyEvent.VK_ENTER); 

robot.keyRelease(KeyEvent.VK_ENTER);

@Rupesh and @Artjom B. Thanks @Rupesh和@Artjom B.谢谢

I checked and both of your answers are working. 我检查了一下,您的答案都起作用了。

But the real problem was at the button where error msg pops up. 但是真正的问题是出现错误消息的按钮。 so i added sleep before remove button on which popup occurs and this is working with both of your answers. 所以我在出现弹出窗口的删除按钮之前添加了睡眠,这与您的两个答案都一样。

Thread.sleep(1000);
objBrowser.findElement(By.cssSelector("input[Value='Remove']")).click();

objBrowser.findElement(By.xpath("//button[contains(span/text(), 'OK')]")).click();

暂无
暂无

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

相关问题 无法单击Selenium中的按钮 - Not able to click a button in Selenium 弹出窗口 window 无法单击模态下的确定按钮 window class - Selenium [JAVA] - PopUp window not able to click on OK button which Is under Modal window class - Selenium [JAVA] 无法在Selenium WebDriver中单击按钮 - Not able to click on a button in selenium webdriver 无法在Java Selenium中单击按钮? - Not able to click on button in java selenium? 无法在Selenium Webdriver上单击按钮(元素) - Not able to click Button(element) on Selenium webdriver Selenium Web 驱动程序无法单击前台对话框的确定​​按钮并找到后台对话框的确定​​按钮 - Selenium web driver fails to click to foreground dialog's OK button and finds background dialog's OK button 在Selenium Web驱动程序中,我可以单击“保存”按钮,然后保存页面,但是它没有显示此类元素错误消息,无法继续 - In selenium web driver,I can able to click the save button then page getting saved but it shows no such element error message not able to go futher 点击硒中的模态警报确定 - Click on alert ok on modal in selenium 用PhantomJS Selenium Java无法点击popup allert消息“OK或Cancel”,与IE一起正常工作 - Not able to click on popup allert message“OK or Cancel” with PhantomJS Selenium Java, working fine with IE 不能单击“搜索”按钮Selenium Web Driver Java - Not Able to click on “Search” button Selenium Web Driver Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM