Reputation: 155
In my page I open a prompt with the following code:
prompt('CopyURL','http://www.google.com');
In protractor I can get the text but I don't know how to get the value. For getting the text I use the following code:
var alertDialog = browser.switchTo().alert();
expect(alertDialog.getText()).toEqual('Copy URL');
How do I get 'http://www.google.com'
with protractor?
Thank you!!
Upvotes: 2
Views: 533
Reputation: 6962
Currently there is no way to do it. However, prompt's were designed for user to enter a value rather than get the value that you pass in the html code. If you are using the value that's passed in the prompt some where in your DOM, then you can get the value of that element and verify with the passed element. Here's a sample method -
HTML Code -
<button onclick="myFunction()">Open Prompt</button>
<p id="demo"></p>
Javascript Code -
function myFunction() {
var val = prompt("Name", "abc");
if (val != null) {
document.getElementById("demo").innerHTML = val;
}
}
As demonstrated above, you can get the value passed to the prompt by verifying the value stored in the p element of html. However if you just want to show a value to the user, in this case your url, then a normal alert should be considered in place of prompt i believe. Hope it helps.
Upvotes: 1