admin管理员组文章数量:1410725
I need to read the text displayed on the popup window in Web driver using Java. I am able to handle the popup window for closing. I don't know how to read the text displayed on Popup window and print it in Console.
I am not able to provide any HTML code for this because its a Modal Popup window.
Please help me on this. Help will be appreciated.
I need to read the text displayed on the popup window in Web driver using Java. I am able to handle the popup window for closing. I don't know how to read the text displayed on Popup window and print it in Console.
I am not able to provide any HTML code for this because its a Modal Popup window.
Please help me on this. Help will be appreciated.
Share Improve this question asked Feb 27, 2013 at 6:45 Umamaheshwar ThotaUmamaheshwar Thota 5213 gold badges14 silver badges32 bronze badges 4- if this is your application, shouldn't you be able to capture the message you're gonna display on the pop-up? – Rahul Commented Feb 27, 2013 at 6:46
- Thanks for your early reply. It is the application i am working on but message displayed on Popup window is not able to read because it is a modal popup window not a normal popup where we can work without closing the popup window. without closing the Modal Popup window, we cannot work on the application anymore. – Umamaheshwar Thota Commented Feb 27, 2013 at 6:55
- And that popup - is it javascript popup? – Pavel Janicek Commented Feb 27, 2013 at 7:55
- I found this describing how to get the text of an alert box: – VolkerK Commented Feb 27, 2013 at 7:57
2 Answers
Reset to default 2Given your screenshot, it looks like the "modal popup" you're trying to automate is generated by the JavaScript alert() function. If this is the case, the following code or something similar to it, should work.
// WARNING! Untested code written from memory without
// benefit of an IDE! May not be exactly correct!
// Switch the driver context to the alert
Alert alertDialog = driver.switchTo().alert();
// Get the alert text
String alertText = alertDialog.getText();
// Click the OK button on the alert.
alertDialog.accept();
Have you used the WebDriverWait object before? To expand on the previous answer, you may be able to do something similar to this, but I have not tested:
WebDriverWait wait = new WebDriverWait(5, TimeUnit.Seconds);
element.click();
// Wait for the dialog to show
wait.until(ExpectedConditions.alertIsPresent());
// Switch the driver context to the alert
Alert alertDialog = driver.switchTo().alert();
// Get the alert text
String alertText = alertDialog.getText();
// Click the OK button on the alert.
alertDialog.accept();
Also, you may have to switch back to the alert after getting the text. Hope this helps.
版权声明:本文标题:javascript - I need to read the text displayed on the popup window in Web driver using Java - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744835972a2627631.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论