Get text from leave site alert using JavaScript? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Is there any way to get the text from an alert in JavaScript?
Below I have attached the screenshot of an alert.
Actually I am trying to automate a website using selenium and java and selenium isn't able to handle such alert.
I wonder whether the JavaScript has solution to such alerts.
I am not aware of JavaScript syntax and code styling so posting only a question. Please excuse me for this.
driver.switchTo.alert().getText()
only works for if it is a JS alert,if it is browser alert then it doesn't work
ALERT EXAMPLE:

You should try this, with Selenium:
Alert alert = driver.switchTo().alert();
alert.getText();

The only way I know to do this within javascript is using the confirm popup. It has generic 'OK' and 'Cancel' buttons which I don't believe can be edited and is formatted according to the users web browser. To use the confirm method you write:
if (confirm("Do you really want to leave here?"){
//do whatever
}

Related

Is there a way to hide the fact that you minimize the browser or unfocus from some window [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So I was wondering if there is a way to hide you're activity from a webpage that uses JavaScript (And libraries such as AjaX or JQuery).
By activity I mean that I don't what the webpage to know that I'm switching tabs or minimizing the browser, unfocusing and etc.
I know you can track someones activity like so:
$(window).focus(function() {
console.log("YOU'RE BACK")
});
$(window).blur(function() {
console.log("YOU'RE OUT")
});
And I can stop it by writing the following in the console:
$(window).off()
But I'm sure there are million other ways to do so, and I want to make sure that any specific webpage doesn't do so.
So, How can I make sure that no sensitive information leaked?
also note that I don't want to block JavaScript completely, because I want the webpage to still work.

Autofilling a different webpage with user input [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to find out how I can make a program in JavaScript/HTML that takes a user's input and automatically enters this information onto a different web page. I am new to JavaScript/HTML so any help would be appreciated!
You specified the website as:
Supreme
Now, when you go to checkout, right click and click Inspect Elements. Then find all of the input fields on the website. For example, I found the Full Name input field. The field has a name: order[billing_name]
What you want to do next is in your URL do something like this:
https://www.supremenewyork.com/checkout?order[billing_name]=yourname
Now if you want multiple values (most likely) you need to find the names of the other fields and add the values to the URL, as so:
https://www.supremenewyork.com/checkout?order[billing_name]=yourname&order[email]=youremail
This way you can pass the values from your application and fill in the form on that website.
Hope this helps.
Use localstorage. see working demo in the link below;
Note: localStorage won't work in snippet; hence I made a fiddle.

javascript debug who is blocking form submit [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a lot JS files in legacy project. Some JS code is blocking form submit, how I can find what JS events is listening form submit ?
Chrome actually has a great tool that is able to do this. Right-click on the submit button and open dev tools. Then go to event listeners in the sub tab from there you should be able to see the submit action. You can expand the action and view the source.
the comments are a good start, additionally search through all files for any reference to the forms name or id and if thats not enout for any code looping through all forms.
depending on the techniques used, e.g. jquery you might need to change your search like
document.getElementsByTagName("form")
$("form")
$("#ID_OF_FORM).submit
and so on... i guess best chances by using the ID of the form
You can also add event listener in Console Tab.
More in article below.
How to debug Front-end: Console

ASP.NET change text with no page refresh on button click [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I've found a couple other threads containing the same questions, but none of them had an understandable answer. I am supposed to make client side changes, but that is only possible in the .ascx file and if for instance i want to call a function to calculate something and then display it with no page refresh that is not possible :( any easy solutions?
With jquery, you can replace the contents of any existing HTML element using the .html() function. For example,
$("#MyDiv").html("Here is the new text.");
Since the function takes HTML as an input, you can even set the style if you want:
$("#MyDiv").html("Here is some text. <DIV class='foo'>Here is some more text in a different style.</DIV>");
You can also add new elements using .append(), like this:
$("#MyDiv").append("<p>Even more text</p>");
To do this upon a button click, you would use the .click() function. So your code would look something like this:
$("#MyButton").click(function() {
$("#MyDiv").html("You just clicked a button!");
});

I want to make a Javascript browser scripts in console. What syntax is there to click/enter text/find values? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Im a beginner in JavaScript and I want to make scripts in the console of the browser to do tasks. I cant find the syntax to do this. The only command I know of is document.getElementById() however Im struggling to find commands to click or enter text into a search box or something to input text in.
Does anyone know how to do this?
Example of what I want to achieve:
Type Hello into the google search bar and press enter.
Also why has this question been put on hold it got answered...
You could use ruby with Capybara and Cucumber to do that https://github.com/jnicklas/capybara and if you still want to use javascript you can inspect the input and get the id and then do this:
document.getElementById('lst-ib').value = "Hello";
and for the click you could try this:
document.getElementsByName('btnK')[0].click();
but it didn't work for me.
And if you want to learn javascript you can do it in codeschool or codecademy for example.
The best start will be: http://www.w3schools.com/js/
It has a lot of examples and will help you to make the first steps;)

Categories

Resources